From fb866e00117a5db5b07b8c0643f0b2c932a53c43 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Sat, 12 Aug 2017 16:37:01 +0300 Subject: [PATCH 1/6] add terminate option --- web/ssh-tunnelier | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/ssh-tunnelier b/web/ssh-tunnelier index 3a86766..7ba727a 100755 --- a/web/ssh-tunnelier +++ b/web/ssh-tunnelier @@ -113,9 +113,10 @@ while true; do this_pid="$( get_pid "${ids[$j]}" )" [[ -n "$this_pid" ]] && { # PID exists, ask to kill - printf "\n ${colRow}k kill?${colZ}\n" + printf "\n ${colRow}k kill?\n t terminate?${colZ}\n" read -t 600 input2 [[ "$input2" = "k" ]] && kill $( get_pid "${ids[$j]}" ) + [[ "$input2" = "t" ]] && kill -9 $( get_pid "${ids[$j]}" ) } [[ -z "$this_pid" ]] && { # PID empty, run From 712ee7bc02e067053c3692af9a63f14af81c2334 Mon Sep 17 00:00:00 2001 From: q Date: Wed, 16 Aug 2017 15:25:27 +0300 Subject: [PATCH 2/6] terminate ssh tunnels --- web/ssh-tunnelier | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/ssh-tunnelier b/web/ssh-tunnelier index 3a86766..0a36ffc 100755 --- a/web/ssh-tunnelier +++ b/web/ssh-tunnelier @@ -113,9 +113,10 @@ while true; do this_pid="$( get_pid "${ids[$j]}" )" [[ -n "$this_pid" ]] && { # PID exists, ask to kill - printf "\n ${colRow}k kill?${colZ}\n" + printf "\n ${colRow}k kill\n ${colRow}t terminate${colZ}\n" read -t 600 input2 [[ "$input2" = "k" ]] && kill $( get_pid "${ids[$j]}" ) + [[ "$input2" = "t" ]] && kill -9 $( get_pid "${ids[$j]}" ) } [[ -z "$this_pid" ]] && { # PID empty, run From 51b11799268f721c406c6132335a6e756fd04dfe Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Wed, 16 Aug 2017 16:57:07 +0300 Subject: [PATCH 3/6] ansi codes printer --- bin/ansi-codes | 7 +++++++ reporting/ansi.py | 48 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100755 bin/ansi-codes diff --git a/bin/ansi-codes b/bin/ansi-codes new file mode 100755 index 0000000..a1edef1 --- /dev/null +++ b/bin/ansi-codes @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +import sys,os +sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), + "..","reporting"))) +import ansi +ansi.demo() diff --git a/reporting/ansi.py b/reporting/ansi.py index 0d46c26..2bba08d 100644 --- a/reporting/ansi.py +++ b/reporting/ansi.py @@ -38,13 +38,13 @@ class code: io = '\033[27m'#inverse off st = '\033[9m'#strike on so = '\033[29m'#strike off - CLRLIN = '\033[2J' + CLR = '\033[2J' CLREND = '\033[K' CLRBEG = '\033[1K' - CLRSCR = CLRLIN+"\033[0;0H" + CLRSCR = CLR+"\033[0;0H" - color_keys="K,R,G,B,Y,M,C,W,k,r,g,b,y,m,c,w,S,s,U,u,Z,ic,io,st,so,bk,br,bg,by,bb,bm,bc,bw,CLRLIN,CLREND,CLRBEG,CLRSCR".split(",") - color_list=[K,R,G,B,Y,M,C,W,k,r,g,b,y,m,c,w,S,s,U,u,Z,ic,io,st,so,bk,br,bg,by,bb,bm,bc,bw,CLRLIN,CLREND,CLRBEG,CLRSCR] + color_keys="K,R,G,B,Y,M,C,W,k,r,g,b,y,m,c,w,S,s,U,u,Z,ic,io,st,so,bk,br,bg,by,bb,bm,bc,bw,CLR,CLREND,CLRBEG,CLRSCR".split(",") + color_list=[K,R,G,B,Y,M,C,W,k,r,g,b,y,m,c,w,S,s,U,u,Z,ic,io,st,so,bk,br,bg,by,bb,bm,bc,bw,CLR,CLREND,CLRBEG,CLRSCR] custom_match=re.compile(r'(\${)([0-9;]*[ABCDEFGHJKSTfminsu]+)(})') def pos(self,y,x): @@ -101,3 +101,43 @@ class code: def get_keys(self): return self.color_keys + + + + +def demo(): + """ Print all control sequences """ + c=code() + unformatted="""${S}ANSI CODES +==========${Z} +${S}Fo${U}rm${st}at${u}ti${ic}ng${Z} +${S}==========${Z} + 0 Z Clear format + 1 S ${S}Strong ${Z} 2 s ${s}Off${Z} + 4 U ${U}Underline${Z} 24 u Off + 7 ic ${ic}Inverse${Z} 27 io Off + 9 st ${st}Strike${Z} 29 so Off +${R}Co${G}lo${B}rs${Z} +${S}======${Z} + 30 k ${k}Black ${Z}1 K ${K}Strong ${Z}40 bk ${bk}Background${Z} + 31 r ${r}Red ${Z}1 R ${R}Strong ${Z}41 br ${br}Background${Z} + 32 g ${g}Green ${Z}1 G ${G}Strong ${Z}42 bg ${bg}Background${Z} + 33 y ${y}Yellow ${Z}1 Y ${Y}Strong ${Z}43 by ${by}Background${Z} + 34 b ${b}Blue ${Z}1 B ${B}Strong ${Z}44 bb ${bb}Background${Z} + 35 m ${m}Magenta ${Z}1 M ${M}Strong ${Z}45 bm ${bm}Background${Z} + 36 c ${c}Cyan ${Z}1 C ${C}Strong ${Z}46 bc ${bc}Background${Z} + 37 w ${w}White ${Z}1 W ${W}Strong ${Z}47 bw ${bw}Background${Z} +${S}Clearing and movement +${S}=====================${Z} + 2J CLR Clear screen + 2J ;H CLRSCR .clear() Clear screen and cursor to upper left + K CLREND Clear to end of line + 1K CLRBEG Clear to beginning of line + + s .save() Save location u .restore() Restore location + A .up() Up E .up_line() Up line + B .down() Down F .down_line() Down line + C .left() Left x;yH .pos() Absolute Position + D .right() Right """ + + print(c.color_string(unformatted)) From eb4b1016fae73a6712477a656f3897c91b303100 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Thu, 17 Aug 2017 18:41:38 +0300 Subject: [PATCH 4/6] coloring demo for qolop --- reporting/ansi.py | 2 +- reporting/qolop | 94 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 22 deletions(-) mode change 100644 => 100755 reporting/qolop diff --git a/reporting/ansi.py b/reporting/ansi.py index 2bba08d..7f2cf9c 100644 --- a/reporting/ansi.py +++ b/reporting/ansi.py @@ -137,7 +137,7 @@ ${S}=====================${Z} s .save() Save location u .restore() Restore location A .up() Up E .up_line() Up line B .down() Down F .down_line() Down line - C .left() Left x;yH .pos() Absolute Position + C .left() Left y;xH .pos() Absolute Position D .right() Right """ print(c.color_string(unformatted)) diff --git a/reporting/qolop b/reporting/qolop old mode 100644 new mode 100755 index 8ab47e9..ec29520 --- a/reporting/qolop +++ b/reporting/qolop @@ -1,21 +1,26 @@ -# Quick shell COLOrizer Package -# Source in BASH +#!/bin/bash -# Version 2017.08.08.1 -# Examples: -# As functions: -# _title(){ _qCol z G; } -# _z(){ _qCol z; } -# _title; echo Title; _z +_qColHelp() { + echo 'Quick shell COLOrizer Package +Source me in BASH! -# As variables -# TITLE=$( _qCol z G; ) -# Z=$( _qCol z; ) -# echo ${TITLE}Title${Z} +Version 2017.08.17.0 +Examples: +- As functions: + _title(){ _qCol z G; } + _z(){ _qCol z; } + _title; echo Title; _z -# Export to variables (prefixed with _c. Also the default) -# _qCol export _c -# echo -e ${_cG}Title${_cZ} +- As variables + TITLE=$( _qCol z G; ) + Z=$( _qCol z; ) + echo ${TITLE}Title${Z} + +- Export to variables (prefixed with _c. Also the default) + _qCol export _c + echo -e ${_cG}Title${_cZ} +' +} _qCol() { # print "easier" mapping of ANSI colors and controls @@ -56,12 +61,12 @@ _qCol() { local io='\033[27m' #inverse off local st='\033[9m' #strike on local so='\033[29m' #strike off - local CLRLIN='\033[2J' # Clear line + local CLR='\033[2J' # Clear screen local CLREND='\033[K' # Clear to end of line local CLRBEG='\033[1K' # Clear to beginning of line - local CLRSCR="$CLRLIN"'\033[0;0H' # Clear screen + local CLRSCR="$CLR"'\033[0;0H' # Clear screen, reset cursor - local color_keys=" K R G B Y M C W k r g b y m c w S s U u z Z ic io st so bk br bg by bb bm bc bw CLRLIN CLREND CLRBEG CLRSCR " + local color_keys=" K R G B Y M C W k r g b y m c w S s U u z Z ic io st so bk br bg by bb bm bc bw CLR CLREND CLRBEG CLRSCR " [[ "$1" = "export" ]] && { local key @@ -82,7 +87,7 @@ _qCol() { } _qCode() { - # Enter numerical ANSI codes directly + # Enter numerical ANSI colors directly local arg val for ((arg=1;arg<=$#;arg++)) { val=${!arg} @@ -102,9 +107,56 @@ _qPos() { [[ "$1" = "down" ]] && { printf '\033['${n}'B'; return; } [[ "$1" = "right" ]] && { printf '\033['${n}'C'; return; } [[ "$1" = "left" ]] && { printf '\033['${n}'D'; return; } - [[ "$1" = "linedown" ]] && { printf '\033['${n}'E'; return; } - [[ "$1" = "lineup" ]] && { printf '\033['${n}'F'; return; } + [[ "$1" = "lineup" ]] && { printf '\033['${n}'E'; return; } + [[ "$1" = "linedown" ]] && { printf '\033['${n}'F'; return; } [[ "$1" = "col" ]] && { printf '\033['${n}'G'; return; } [[ "$1" = "abs" ]] && { printf '\033['${n}';'${x}'H'; return; } } +_qClr() { + # Clear screen + _qCol "CLR" + _qPos abs 0 0 +} + +[[ "$0" = "${BASH_SOURCE[0]}" ]] && { + echo This script should be sourced + _qColHelp + + _qCol export "_" + printf "${_S}ANSI CODES AND QOLOP VARIABLES +==============================${_Z} +${_S}Fo${_U}rm${_st}at${_u}ti${_ic}ng${_Z} +${_S}==========${_Z} + 0 Z Clear format + 1 S ${_S}Strong ${_Z} 2 s ${_s}Off${_Z} + 4 U ${_U}Underline${_Z} 24 u Off + 7 ic ${_ic}Inverse${_Z} 27 io Off + 9 st ${_st}Strike${_Z} 29 so Off +${_R}Co${_G}lo${_B}rs${_Z} +${_S}======${_Z} + 30 k ${_k}Black ${_Z}1 K ${_K}Strong ${_Z}40 bk ${_bk}Background${_Z} + 31 r ${_r}Red ${_Z}1 R ${_R}Strong ${_Z}41 br ${_br}Background${_Z} + 32 g ${_g}Green ${_Z}1 G ${_G}Strong ${_Z}42 bg ${_bg}Background${_Z} + 33 y ${_y}Yellow ${_Z}1 Y ${_Y}Strong ${_Z}43 by ${_by}Background${_Z} + 34 b ${_b}Blue ${_Z}1 B ${_B}Strong ${_Z}44 bb ${_bb}Background${_Z} + 35 m ${_m}Magenta ${_Z}1 M ${_M}Strong ${_Z}45 bm ${_bm}Background${_Z} + 36 c ${_c}Cyan ${_Z}1 C ${_C}Strong ${_Z}46 bc ${_bc}Background${_Z} + 37 w ${_w}White ${_Z}1 W ${_W}Strong ${_Z}47 bw ${_bw}Background${_Z} + Enter raw color codes with _qCode function +${_S}Clearing and movement +${_S}=====================${_Z} + 2J CLR Clear screen + 2J ;H CLRSCR _qClr() Clear screen and cursor to upper left + K CLREND Clear to end of line + 1K CLRBEG Clear to beginning of line + + s _qPos save Save location u _qPos restore Restore location + A _qPos up Up E _qPos lineup Up line + B _qPos down Down F _qPos linedown Down line + C _qPos left Left y;xH _qPos abs y x Absolute Position + D _qPos right Right +" + +} + From ddbee4ddee81cb2cf3878f6c114d49ea0577705a Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Fri, 18 Aug 2017 10:45:25 +0300 Subject: [PATCH 5/6] tiny qolop docs fix --- reporting/qolop | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reporting/qolop b/reporting/qolop index ec29520..ac1227e 100755 --- a/reporting/qolop +++ b/reporting/qolop @@ -6,6 +6,7 @@ Source me in BASH! Version 2017.08.17.0 Examples: + source qolop # load functions - As functions: _title(){ _qCol z G; } _z(){ _qCol z; } @@ -120,7 +121,6 @@ _qClr() { } [[ "$0" = "${BASH_SOURCE[0]}" ]] && { - echo This script should be sourced _qColHelp _qCol export "_" @@ -157,6 +157,5 @@ ${_S}=====================${_Z} C _qPos left Left y;xH _qPos abs y x Absolute Position D _qPos right Right " - } From cfa0e6bf67db4a2fbb9fac709f5631f16829091e Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Fri, 18 Aug 2017 19:43:50 +0300 Subject: [PATCH 6/6] again improving qolop table --- reporting/qolop | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/reporting/qolop b/reporting/qolop index ac1227e..fa3e106 100755 --- a/reporting/qolop +++ b/reporting/qolop @@ -20,6 +20,8 @@ Examples: - Export to variables (prefixed with _c. Also the default) _qCol export _c echo -e ${_cG}Title${_cZ} + +Run qolop as script to print ANSI code table ' } @@ -122,18 +124,20 @@ _qClr() { [[ "$0" = "${BASH_SOURCE[0]}" ]] && { _qColHelp + [[ "$1" = *"help" ]] && exit + [[ "$1" = "-h" ]] && exit _qCol export "_" printf "${_S}ANSI CODES AND QOLOP VARIABLES ==============================${_Z} -${_S}Fo${_U}rm${_st}at${_u}ti${_ic}ng${_Z} +${_S}Fo${_U}rm${_st}at${_u}ti${_ic}ng${_Z} ESC[Xm ${_S}==========${_Z} 0 Z Clear format 1 S ${_S}Strong ${_Z} 2 s ${_s}Off${_Z} 4 U ${_U}Underline${_Z} 24 u Off 7 ic ${_ic}Inverse${_Z} 27 io Off 9 st ${_st}Strike${_Z} 29 so Off -${_R}Co${_G}lo${_B}rs${_Z} +${_R}Co${_G}lo${_B}rs${_Z} ESC[Xm or ESC[X;Y;Zm ${_S}======${_Z} 30 k ${_k}Black ${_Z}1 K ${_K}Strong ${_Z}40 bk ${_bk}Background${_Z} 31 r ${_r}Red ${_Z}1 R ${_R}Strong ${_Z}41 br ${_br}Background${_Z} @@ -144,7 +148,7 @@ ${_S}======${_Z} 36 c ${_c}Cyan ${_Z}1 C ${_C}Strong ${_Z}46 bc ${_bc}Background${_Z} 37 w ${_w}White ${_Z}1 W ${_W}Strong ${_Z}47 bw ${_bw}Background${_Z} Enter raw color codes with _qCode function -${_S}Clearing and movement +${_S}Clearing and movement${_Z} ESC[X or ESC[1X ${_S}=====================${_Z} 2J CLR Clear screen 2J ;H CLRSCR _qClr() Clear screen and cursor to upper left