reorder

Un outil pour réarranger les lignes de stdin - retour accueil

git clone git://bebou.netlib.re/reorder
Log | Files | Refs | README |

commit 7a697a7d4af81b8cdef32cf87f3d21639188f7c7
Auterice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Mon,  1 Jul 2024 16:52:27 +0200

Premier commit

Faire seq 10 | ./reorder

Diffstat:
AREADME | 5+++++
Areorder | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/README b/README @@ -0,0 +1,5 @@ +Un outil pour réarranger les lignes de stdin + +Dans le but d'être une interface pour le pipe-card-game + +Un POC, dépend salement de xev diff --git a/reorder b/reorder @@ -0,0 +1,61 @@ +#! /bin/sh + +reset() { + sed -i "s/\[91m//g;s/\[92m//g" $file +} + +swaplines() { + paste -s | + awk "BEGIN{OFS=\"\n\"}{a=\$$1;\$$1=\$$2;\$$2=a}1" +} + +modify() { + clear + tput cup 0 0 + case "$mode" in + (Looking) + cat $file | + sed "$1 s/^/\x1b[91m/;s/$/\x1b[0m/" ;; + (Selecting) + cat $file | + swaplines $1 $2 | + sed "$1 s/^/\x1b[92m/;s/$/\x1b[0m/" | + tee $file ;; + (*) + break ;; + esac +} + +clear + +file="/tmp/a" +cat > $file + +curline="1" +prevline="1" +lastline=$(< $file wc -l) +mode="Looking" +modify $curline $prevline + +xev | + stdbuf -o0 grep "KeyPress" -A2 | + stdbuf -o0 grep -Eo "(Up|Down|Return)" | + while read key;do + case "$key" in + (Up) + [ $curline = "1" ] && continue + prevline=$curline; + curline=$(( $curline - 1 )) ;; + (Down) + [ $curline = $lastline ] && continue + prevline=$curline + curline=$(( $curline + 1 )) ;; + (Return) + prevline=$curline + [ "$mode" = "Looking" ] && mode="Selecting" || mode="Looking" + reset ;; + (*) break ;; + esac + modify $curline $prevline + echo $key + done