Commit 03ce009e authored by epsi sayidina's avatar epsi sayidina

pipe and fork, add lemon

parent e99d07ae
#!/usr/bin/env bash
function get_lemon_parameters() {
# geometry: -g widthxheight+x+y
xpos=0
ypos=0
width=640
height=24
geom_res="${width}x${height}+${xpos}+${ypos}"
# color, with transparency
fgcolor="#000000"
bgcolor="#aaffffff"
# XFT: require lemonbar_xft_git
local font="monospace-9"
# finally
parameters=" -g $geom_res -u 2"
parameters+=" -B $bgcolor -F $fgcolor"
parameters+=" -f $font"
}
function generated_output() {
dirname=$(dirname $(readlink -f "$0"))
path="$dirname/../assets"
conky -c "$path/conky.lua"
}
function run_lemon() {
get_lemon_parameters
command_out="lemonbar $parameters"
{
generated_output
} | $command_out
}
function detach_lemon() {
run_lemon &
}
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# main
# remove all lemon instance
pkill lemonbar
# run process in the background
detach_lemon
import System.Process
import System.Directory
import System.IO
import System.Posix.Process
import System.Posix.Types
import Control.Concurrent
import Control.Monad
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- wrap Funktion
cmdin = "conky"
cmdout = "lemonbar"
-- Source directory is irrelevant in Haskell
-- but we'll do it anyway for the sake of learning
wConkyFileName :: String -> String
wConkyFileName dirName = dirName ++ "/../assets" ++ "/conky.lua"
getLemonParameters :: [String]
getLemonParameters = [
"-g", geom_res, "-u", "2",
"-B", bgcolor, "-F", fgcolor,
"-f", font
]
where
-- geometry: -g widthxheight++y
xpos = "0"
ypos = "0"
width = "640"
height = "24"
geom_res = width ++ "x" ++ height
++ "+" ++ xpos ++ "+" ++ ypos
-- color, with transparency
fgcolor = "#000000"
bgcolor = "#aaffffff"
-- XFT: require lemonbar_xft_git
font = "monospace-9"
wSleep :: Int -> IO ()
wSleep mySecond = threadDelay (1000000 * mySecond)
detachLemon :: IO ()
detachLemon = do
dirName <- getCurrentDirectory
let conkyFileName = wConkyFileName dirName
(_, Just pipeout, _, _) <-
createProcess (proc cmdin ["-c", conkyFileName])
{ std_out = CreatePipe }
(_, _, _, ph) <-
createProcess (proc cmdout getLemonParameters)
{ std_in = UseHandle pipeout }
hClose pipeout
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- main
main = do
-- remove all lemonbar instance
system "pkill lemonbar"
-- run process in the background
detachLemon
-- end of IO
return ()
#!/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
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- application related function
function get_lemon_parameters ()
-- geometry: -g widthxheight+x+y
local xpos = '0'
local ypos = '0'
local width = '640'
local height = '24'
local geom_res = width .. 'x' .. height
.. '+' .. xpos .. '+' .. ypos
-- color, with transparency
local fgcolor = "'#000000'"
local bgcolor = "'#aaffffff'"
-- XFT: require lemonbar_xft_git
local font = "monospace-9"
-- finally
local parameters = ""
.. " -g "..geom_res.." -u 2"
.. " -B "..bgcolor.." -F "..fgcolor
.. " -f "..font
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_lemon ()
local cmdout = 'lemonbar ' .. get_lemon_parameters()
local pipeout = assert(io.popen(cmdout, 'w'))
generated_output(pipeout)
pipeout:close()
end
function detach_lemon()
local pid = posix.fork()
if pid == 0 then -- this is the child process
run_lemon()
else -- this is the parent process
-- nothing
end
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- main
-- remove all lemonbar instance
os.execute('pkill lemonbar')
-- run process in the background
detach_lemon()
......@@ -18,8 +18,7 @@ sub get_dzen2_parameters {
$parameters .= " -fn '$font'";
$parameters .= " -ta c -bg '$bgcolor' -fg '$fgcolor'";
$parameters .= " -title-name dzentop";
# print $parameters . "\n";
return $parameters;
}
......
......@@ -18,8 +18,7 @@ sub get_dzen2_parameters {
$parameters .= " -fn '$font'";
$parameters .= " -ta c -bg '$bgcolor' -fg '$fgcolor'";
$parameters .= " -title-name dzentop";
# print $parameters . "\n";
return $parameters;
}
......
#!/usr/bin/perl
use warnings;
use strict;
use File::Basename;
use IO::Pipe;
sub get_lemon_parameters {
# geometry: -g widthxheight+x+y
my $xpos = 0;
my $ypos = 0;
my $width = 640;
my $height = 24;
my $geom_res = "${width}x${height}+${xpos}+${ypos}";
# color, with transparency
my $fgcolor = "#000000";
my $bgcolor = "#aaffffff";
# XFT: require lemonbar_xft_git
my $font = "monospace-9";
# finally
my $parameters = " -g $geom_res -u 2"
. " -B $bgcolor -F $fgcolor"
. " -f $font";
return $parameters;
}
sub generated_output {
my $pipeout = shift;
my $pipein = IO::Pipe->new();
my $dirname = dirname(__FILE__);
my $path = "$dirname/../assets";
my $cmd = "conky -c $path/conky.lua";
my $handle = $pipein->reader($cmd);
while(<$pipein>) {
print $pipeout $_;
flush $pipeout;
}
$pipein->close();
}
sub run_lemon {
my $pipeout = IO::Pipe->new();
my $cmd = "lemonbar " . get_lemon_parameters();
my $handle = $pipeout->writer($cmd);
generated_output($pipeout);
$pipeout->close();
}
sub detach_lemon {
my $pid = fork;
return if $pid; # in the parent process
run_lemon();
exit;
}
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# main
# remove all lemon instance
system('pkill lemonbar');
# run process in the background
detach_lemon();
#!/usr/bin/php
<?php # using PHP7
function get_lemon_parameters()
{
# geometry: -g widthxheight+x+y
$xpos = 0;
$ypos = 0;
$width = 640;
$height = 24;
$geom_res = "${width}x${height}+${xpos}+${ypos}";
# color, with transparency
$fgcolor = "'#000000'";
$bgcolor = "'#aaffffff'";
# XFT: require lemonbar_xft_git
$font = 'monospace-9';
# finally
$parameters = " -g $geom_res -u 2"
. " -B $bgcolor -F $fgcolor"
. " -f $font";
return $parameters;
}
function generated_output($process)
{
$path = __dir__."/../assets";
$cmdin = 'conky -c '.$path.'/conky.lua';
$pipein = popen($cmdin, "r"); # handle
while(!feof($pipein)) {
$buffer = fgets($pipein);
fwrite($process, $buffer);
flush();
}
pclose($pipein);
}
function run_lemon()
{
$cmdout = 'lemonbar '.get_lemon_parameters();
$pipeout = popen($cmdout, "w");
generated_output($pipeout);
pclose($pipeout);
}
function detach_lemon()
{
$pid = pcntl_fork();
switch($pid) {
case -1 : die('could not fork'); // fork errror
case 0 : run_lemon(); break; // we are the child
default : return $pid; // we are the parent
}
}
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# main
# remove all lemonbar instance
system('pkill lemonbar');
# run process in the background
detach_lemon();
......@@ -20,7 +20,7 @@ def get_dzen2_parameters():
parameters += " -ta c -bg '"+bgcolor+"' -fg '"+fgcolor+"'"
parameters += ' -title-name dzentop'
return parameters;
return parameters
def generated_output(pipeout):
dirname = os.path.dirname(os.path.abspath(__file__))
......
#!/usr/bin/env python3
import datetime
import time
import subprocess
import os
import signal
def get_lemon_parameters():
# geometry: -g widthxheight+x+y
xpos = '0'
ypos = '0'
width = '640'
height = '24'
geom_res = width + 'x' + height + '+' + xpos + '+' + ypos
# color, with transparency
fgcolor = "'#000000'"
bgcolor = "'#aaffffff'"
# XFT: require lemonbar_xft_git
font = "monospace-9"
# finally
parameters = ' -g ' + geom_res + ' -u 2 ' \
+ ' -B ' + bgcolor + ' -F ' + fgcolor \
+ ' -f ' + font
return parameters
def generated_output(pipeout):
dirname = os.path.dirname(os.path.abspath(__file__))
path = dirname + "/../assets"
cmdin = 'conky -c ' + path + '/conky.lua'
pipein = subprocess.Popen(
[cmdin],
stdout = pipeout.stdin,
stderr = subprocess.STDOUT,
shell = True,
universal_newlines = True
)
def run_lemon():
cmdout = 'lemonbar '+get_lemon_parameters()
pipeout = subprocess.Popen(
[cmdout],
stdin = subprocess.PIPE,
shell = True,
universal_newlines=True
)
generated_output(pipeout)
pipeout.stdin.close()
outputs, errors = pipeout.communicate()
# avoid zombie apocalypse
pipeout.wait()
def detach_lemon():
pid = os.fork()
if pid == 0:
try:
run_lemon()
os._exit(1)
finally:
import signal
os.kill(pid, signal.SIGTERM)
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# main
# remove all lemon instance
os.system('pkill lemonbar')
# run process in the background
detach_lemon()
......@@ -7,8 +7,8 @@ def generated_output(stdin)
cmdin = 'conky -c ' + path + '/conky.lua'
IO.popen(cmdin, "r") do |f|
while f do
stdin.puts f.gets
while f do
stdin.puts f.gets
end
f.close()
end
......
......@@ -23,7 +23,7 @@ def generated_output(stdin)
while f do
stdin.puts f.gets
end
f.close()
f.close()
end
end
......
#!/usr/bin/ruby
def get_lemon_parameters()
# geometry: -g widthxheight+x+y
xpos = '0'
ypos = '0'
width = '640'
height = '24'
geom_res = "#{width}x#{height}+#{xpos}+#{ypos}"
# color, with transparency
fgcolor = "'#000000'"
bgcolor = "'#aaffffff'"
# XFT: require lemonbar_xft_git
font = "monospace-9"
parameters = " -g #{geom_res} -u 2" \
" -B #{bgcolor} -F #{fgcolor}" \
" -f #{font}"
end
def generated_output(stdin)
path = __dir__+ "/../assets"
cmdin = 'conky -c ' + path + '/conky.lua'
IO.popen(cmdin, "r") do |f|
while f do
stdin.puts f.gets
end
f.close()
end
end
def run_lemon()
cmdout = 'lemonbar ' + get_lemon_parameters()
IO.popen(cmdout, "w") do |f|
generated_output(f)
f.close()
end
end
def detach_lemon()
# warning: Signal.trap is application wide
Signal.trap("PIPE", "EXIT")
pid = fork { run_lemon() }
Process.detach(pid)
end
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# main
# remove all dzen2 instance
system('pkill lemonbar')
# run process in the background
detach_lemon()
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