From dc2a043f75de7fbdb9b04f88269c699acf06e8c7 Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Mon, 28 Jan 2019 00:49:40 +0100 Subject: Pipes accepted --- data.txt | 64 ------------------------------------------------------------- example.txt | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 54 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 111 insertions(+), 71 deletions(-) delete mode 100644 data.txt create mode 100644 example.txt diff --git a/data.txt b/data.txt deleted file mode 100644 index 80f0b3a..0000000 --- a/data.txt +++ /dev/null @@ -1,64 +0,0 @@ -***XMonad Cheatsheet - -This Text is not to be seen??? -Und Nochmehr TExt der immer Zentriert wird. Schuamamal wie lange es klappt es sollte vll ein Wrap LAbel sein. -##NAAASUPER -Schaumamal ob jetzt der text erkannt wird ---some list - --or some other ideas - WTF--naschau - -##Launching and Killing - - P -- Launch Dmenu - - S -- Launch Synergy - - F -- Launch Nautilus - - -- Launch Terminal - - C -- Kill Focused Window - -##Layout - - -- Rotate through Layouts - - -- Reset Layout of Current Workspace - - N -- Resize Window to Correct size - - B -- Toggle Strouts (Fullestscreen) - - B -- Toggle StatBar - - H -- Shrink Master Area - - L -- Expand Master Area - - T -- Push Floater back to Tiling - - -- Make Window Float and Move - - -- Make Window Float and Resize - - , -- Increase Windows in Master Area - - . -- Decrease Windows in Master Area - - A -- Mirror Shrink - - Y -- Mirror Expand - -##Focus and Order - - -- Focus on Next Window - - -- Focus on Previous Window - - J -- Focus on Next Window - - K -- Focus on Previous Window - - M -- Focus on Master Window - - J -- Swap Focused Window with Next - - K -- Swap Focused Window with Previous - -- Swap Focused with Master - - U -- Focus on Urgent Window - -##Workspaces & Screens - [1-0,-,+] -- Switch to Workspace N - [1-0,-,+] -- Move Window to Workspace N - [w,e,r] -- Switch to Screen 1,2 or 3 - [w,e,r] -- Move Window to Screen 1,2 or 3 - [Arrow Keys] -- Move on Workspace Pattern - - D -- Toggle Single and Multiscreen - -##Login - - Q -- Reload Xmonad - - Ö -- Lock Screen - - Q -- Quit Xmonad and Logout User - -##System - -- Screenshot of current Workspace - - -- Screenshot of All Workspaces - - -- Screenshot of current Window - - Ä -- Display this Help - -//Comments and Empty Lines are Ignored diff --git a/example.txt b/example.txt new file mode 100644 index 0000000..80f0b3a --- /dev/null +++ b/example.txt @@ -0,0 +1,64 @@ +***XMonad Cheatsheet + +This Text is not to be seen??? +Und Nochmehr TExt der immer Zentriert wird. Schuamamal wie lange es klappt es sollte vll ein Wrap LAbel sein. +##NAAASUPER +Schaumamal ob jetzt der text erkannt wird +--some list + --or some other ideas + WTF--naschau + +##Launching and Killing + - P -- Launch Dmenu + - S -- Launch Synergy + - F -- Launch Nautilus + - -- Launch Terminal + - C -- Kill Focused Window + +##Layout + - -- Rotate through Layouts + - -- Reset Layout of Current Workspace + - N -- Resize Window to Correct size + - B -- Toggle Strouts (Fullestscreen) + - B -- Toggle StatBar + - H -- Shrink Master Area + - L -- Expand Master Area + - T -- Push Floater back to Tiling + - -- Make Window Float and Move + - -- Make Window Float and Resize + - , -- Increase Windows in Master Area + - . -- Decrease Windows in Master Area + - A -- Mirror Shrink + - Y -- Mirror Expand + +##Focus and Order + - -- Focus on Next Window + - -- Focus on Previous Window + - J -- Focus on Next Window + - K -- Focus on Previous Window + - M -- Focus on Master Window + - J -- Swap Focused Window with Next + - K -- Swap Focused Window with Previous + -- Swap Focused with Master + - U -- Focus on Urgent Window + +##Workspaces & Screens + [1-0,-,+] -- Switch to Workspace N + [1-0,-,+] -- Move Window to Workspace N + [w,e,r] -- Switch to Screen 1,2 or 3 + [w,e,r] -- Move Window to Screen 1,2 or 3 + [Arrow Keys] -- Move on Workspace Pattern + - D -- Toggle Single and Multiscreen + +##Login + - Q -- Reload Xmonad + - Ö -- Lock Screen + - Q -- Quit Xmonad and Logout User + +##System + -- Screenshot of current Workspace + - -- Screenshot of All Workspaces + - -- Screenshot of current Window + - Ä -- Display this Help + +//Comments and Empty Lines are Ignored diff --git a/main.go b/main.go index bfca0df..b976993 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,10 @@ package main import ( "fmt" "os" + //"io" "bufio" "strings" + "time" "github.com/pborman/getopt/v2" @@ -19,9 +21,9 @@ var ( theme nstyle.Theme = nstyle.DarkTheme dat []data interArgs []string - hea,filename,themestr string + hea,filename,themestr,exitbut string help, border, resize, move, scroll, menubar bool - + countd int = 0 version string compdate string ) @@ -33,20 +35,28 @@ type data struct { } func init() { - filename = "none" + filename = "example.txt" + exitbut = "QUIT" getopt.FlagLong(&border, "no-border", 'b', "Remove Borders") getopt.FlagLong(&resize, "no-resize", 'r', "Prohibit resizing") getopt.FlagLong(&move, "no-translate", 't', "Prohibit window moving") getopt.FlagLong(&scroll, "no-scroll", 's', "Prohibit scrollibars") getopt.FlagLong(&menubar, "no-menu", 'm', "Dont Show Menu") getopt.FlagLong(&scaling, "magnify", 'g', "Magnification level") + getopt.FlagLong(&countd, "count-down", 'd', "Set Count down in seconds for auto-quit") getopt.FlagLong(&themestr, "color-theme", 'c', "Specify Theme") getopt.FlagLong(&help, "help", 'h', "Show Program Usage") getopt.FlagLong(&filename, "file", 'f', "The textfile to be parsed and displayed") + getopt.FlagLong(&exitbut, "quit-button", 'q', "Label of the Quit Button") } func main() { + info, err := os.Stdin.Stat() + if err != nil { + panic(err) + } + getopt.Parse() interArgs = getopt.Args() @@ -55,7 +65,28 @@ func main() { move = !move scroll = !scroll menubar = !menubar + fmt.Println(info) + if info.Mode()&os.ModeCharDevice == os.ModeCharDevice { // || info.Size() <= 0 { + fmt.Println("No Piped Content detected.") + hea,dat = parseFile(loadFile(filename)) + }else{ + hea,dat = parseFile(bufio.NewScanner(os.Stdin)) + + /*reader := bufio.NewReader(os.Stdin) + var output []rune + + for { + input, _, err := reader.ReadRune() + if err != nil && err == io.EOF { + break + } + output = append(output, input) + } + for _,out := range(output) { + fmt.Printf("%c\n", out) + }*/ + } if len(interArgs) > 0 { fmt.Println("Args:",interArgs) } else { @@ -73,7 +104,7 @@ func main() { getopt.Usage() os.Exit(0) } - hea,dat = loadfile("data.txt") + //hea,dat = loadfile(filename) nw := newFenestraWindow() nw.Theme = theme @@ -83,9 +114,18 @@ func main() { Wnd.Main() } -func loadfile(filename string) (head string,out []data){ - f, _ := os.Open(filename) - scanner := bufio.NewScanner(f) +func loadFile(filename string) (out *bufio.Scanner) { + f, err := os.Open(filename) + if err != nil { + //fmt.Println("Filename",filename,"was not found!") + fmt.Println(err) + os.Exit(1) + } + out = bufio.NewScanner(f) + return +} +func parseFile(in *bufio.Scanner) (head string,out []data){ + scanner := in title := "" keys := []string{} info := []string{} -- cgit v1.2.3