Commit 6ffbf597 authored by epsi sayidina's avatar epsi sayidina

standalone: lang

parent 86db0f9f
#!/usr/bin/lua
local timeformat = '%a %b %d %H:%M:%S'
function sleep (n)
local t = os.clock()
while os.clock() - t <= n do
-- nothing
end
end
while true do
print(os.date(timeformat))
sleep(1)
end
#!/usr/bin/lua
local dirname = debug.getinfo(1).source:match("@?(.*/)")
local path = dirname .. "../assets"
local cmdin = 'conky -c ' .. path .. '/conky.lua'
local cmdout = 'less' -- or 'dzen2'
local pipein = assert(io.popen(cmdin, 'r'))
local pipeout = assert(io.popen(cmdout, 'w'))
for line in pipein:lines() do
pipeout:write(line.."\n")
pipeout:flush()
end -- for loop
pipein:close()
pipeout:close()
#!/usr/bin/lua
local timeformat = '%a %b %d %H:%M:%S'
function sleep (n)
local t = os.clock()
while os.clock() - t <= n do
-- nothing
end
end
local cmdout = 'less' -- or 'dzen2'
local pipeout = assert(io.popen(cmdout, 'w'))
while true do
local datestr = os.date(timeformat).."\n"
pipeout:write(datestr)
pipeout:flush()
sleep(1)
end
pipeout:close()
#!/usr/bin/lua
-- luaposix available in AUR
local posix = require "posix"
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- helper
function sleep (n)
local t = os.clock()
while os.clock() - t <= n do
-- nothing
end
end
function exec (command)
local file = assert(io.popen(command, 'r'))
local s = file:read('*all')
file:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- application related function
function get_dzen2_parameters ()
local xpos = '0'
local ypos = '0'
local width = '640'
local height = '24'
local fgcolor = '#000000'
local bgcolor = '#ffffff'
local font = '-*-fixed-medium-*-*-*-12-*-*-*-*-*-*-*'
local parameters = ""
.. " -x "..xpos.." -y "..ypos
.. " -w "..width.." -h "..height
.. " -fn '"..font.."'"
.. " -ta c -bg '"..bgcolor.."' -fg '"..fgcolor.."'"
.. " -title-name dzentop"
return parameters
end
function generated_output (process)
local timeformat = '%a %b %d %H:%M:%S'
while true do
local datestr = os.date(timeformat).."\n"
process:write(datestr)
process:flush()
sleep(1)
end
end
function run_dzen2 ()
local cmdout = 'dzen2 ' .. get_dzen2_parameters()
local pipeout = assert(io.popen(cmdout, 'w'))
generated_output(pipeout)
pipeout:close()
end
function detach_dzen2()
local pid = posix.fork()
if pid == 0 then -- this is the child process
run_dzen2()
else -- this is the parent process
-- nothing
end
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- main
-- remove all dzen2 instance
exec('pkill dzen2')
-- run process in the background
detach_dzen2()
#!/usr/bin/lua
-- luaposix available in AUR
local posix = require "posix"
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- helper
function sleep (n)
local t = os.clock()
while os.clock() - t <= n do
-- nothing
end
end
function exec (command)
local file = assert(io.popen(command, 'r'))
local s = file:read('*all')
file:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- application related function
function get_dzen2_parameters ()
local xpos = '0'
local ypos = '0'
local width = '640'
local height = '24'
local fgcolor = '#000000'
local bgcolor = '#ffffff'
local font = '-*-fixed-medium-*-*-*-12-*-*-*-*-*-*-*'
local parameters = ""
.. " -x "..xpos.." -y "..ypos
.. " -w "..width.." -h "..height
.. " -fn '"..font.."'"
.. " -ta c -bg '"..bgcolor.."' -fg '"..fgcolor.."'"
.. " -title-name dzentop"
return parameters
end
function generated_output (process)
local dirname = debug.getinfo(1).source:match("@?(.*/)")
local path = dirname .. "../assets"
local cmdin = 'conky -c ' .. path .. '/conky.lua'
local pipein = assert(io.popen(cmdin, 'r'))
for line in pipein:lines() do
process:write(line.."\n")
process:flush()
end -- for loop
pipein:close()
end
function run_dzen2 ()
local cmdout = 'dzen2 ' .. get_dzen2_parameters()
local pipeout = assert(io.popen(cmdout, 'w'))
generated_output(pipeout)
pipeout:close()
end
function detach_dzen2()
local pid = posix.fork()
if pid == 0 then -- this is the child process
run_dzen2()
else -- this is the parent process
-- nothing
end
end
function detach_transset()
local pid = posix.fork()
if pid == 0 then -- this is the child process
sleep(1)
exec('transset .8 -n dzentop >/dev/null 2')
else -- this is the parent process
-- nothing
end
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- main
-- remove all dzen2 instance
exec('pkill dzen2')
-- run process in the background
detach_dzen2()
-- optional transparency
detach_transset()
#!/usr/bin/perl
# Unidirectional Pipe Example
# A pipe has a read end and a write end.
use warnings;
use strict;
use File::Basename;
my $dirname = dirname(__FILE__);
my $path = "$dirname/../assets";
my $cmdin = "conky -c $path/conky.lua";
my $cmdout = "less"; # or dzen2
open my $pipein, "-|", $cmdin
or die "Could not open filehandle: $!";
open my $pipeout, "|-", $cmdout
or die "Could not open filehandle: $!";
while(<$pipein>) {
print $pipeout $_;
flush $pipeout;
}
close $pipein;
close $pipeout;
......@@ -6,7 +6,6 @@
$path = __dir__."/../assets";
$cmdin = 'conky -c '.$path.'/conky.lua';
$cmdout = 'less'; # or 'dzen2'
$cmd = $cmdin.' | '.$cmdout;
# handle
$pipein = popen($cmdin, "r");
......
#!/usr/bin/env python3
# https://pymotw.com/2/subprocess/
import os
import subprocess
dirname = os.path.dirname(os.path.abspath(__file__))
path = dirname + "/../assets"
cmdin = 'conky -c ' + path + '/conky.lua'
cmdout = 'less -K' # or 'dzen2'
pipein = subprocess.Popen(
[cmdin],
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT,
shell = True,
universal_newlines = True
)
pipeout = subprocess.Popen(
[cmdout],
stdin = pipein.stdout,
shell = True,
universal_newlines = True
)
# http://kendriu.com/how-to-use-pipes-in-python-subprocesspopen-objects
pipein.stdout.close()
outputs, errors = pipeout.communicate()
# avoid zombie apocalypse
pipeout.wait()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment