From 32ed5a2d05b8266b2dd00844dc7b52b3cb91114d Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Sun, 27 Jan 2019 00:55:41 +0100 Subject: Fenestra 0.1 --- data.txt | 56 ++++++++++++++++ main.go | 77 +++++++++++++++++++++ nucuwin.go | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 354 insertions(+) create mode 100644 data.txt create mode 100644 main.go create mode 100644 nucuwin.go diff --git a/data.txt b/data.txt new file mode 100644 index 0000000..9754f16 --- /dev/null +++ b/data.txt @@ -0,0 +1,56 @@ +***XMonad Cheatsheet + +##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 new file mode 100644 index 0000000..a1a2eb8 --- /dev/null +++ b/main.go @@ -0,0 +1,77 @@ +package main + +import ( + //"fmt" + "os" + "bufio" + "strings" + + "github.com/aarzilli/nucular" + _"github.com/aarzilli/nucular/label" + nstyle "github.com/aarzilli/nucular/style" +) + +var ( + scaling = 1.1 + Wnd nucular.MasterWindow + theme nstyle.Theme = nstyle.DarkTheme + dat []data + hea string +) + +type data struct { + title string + textl []string + textr []string +} + + +func main() { + + hea,dat = loadfile("data.txt") + + nw := newNucularWindow() + nw.Theme = theme + + Wnd = nucular.NewMasterWindow(0,hea, nw.nucularWindow) + Wnd.SetStyle(nstyle.FromTheme(theme, scaling)) + Wnd.Main() + +} +func loadfile(filename string) (head string,out []data){ + f, _ := os.Open(filename) + scanner := bufio.NewScanner(f) + title := "" + keys := []string{} + info := []string{} + for scanner.Scan() { + li := scanner.Text() + line := strings.Replace(li,"\t","",-1) + + if strings.HasPrefix(line,"//") { + continue + } + if strings.HasPrefix(line,"***") { + head = line[3:] + continue + } + if strings.HasPrefix(line,"##") { + if title != "" { + out = append(out,data{title,keys,info}) + } + title = line[2:] + keys = nil + info = nil + }else{ + if line != "" { + da := strings.Split(line,"--") + keys = append(keys,da[0]) + info = append(info,da[1]) + } + } + } + + out = append(out,data{title,keys,info}) + return +} + diff --git a/nucuwin.go b/nucuwin.go new file mode 100644 index 0000000..3cde330 --- /dev/null +++ b/nucuwin.go @@ -0,0 +1,221 @@ +package main + +import ( + //"fmt" + "os" + + + "github.com/aarzilli/nucular" + "github.com/aarzilli/nucular/label" + nstyle "github.com/aarzilli/nucular/style" + "github.com/aarzilli/nucular/rect" + //ncommand "github.com/aarzilli/nucular/command" + + //"golang.org/x/mobile/event/key" + //"golang.org/x/mobile/event/mouse" +) + + +type nucularWindow struct { + ShowMenu bool + Titlebar bool + Border bool + Resize bool + Movable bool + NoScrollbar bool + Minimizable bool + Close bool + + HeaderAlign nstyle.HeaderAlign + + // Menu status + Mprog int + Mslider int + Mcheck bool + Prog int + Slider int + Check bool + + Theme nstyle.Theme +} + +func newNucularWindow() (nw *nucularWindow) { + nw = &nucularWindow{} + nw.ShowMenu = true + nw.Titlebar = true + nw.Border = true + nw.Resize = true + nw.Movable = true + nw.NoScrollbar = false + nw.Close = true + + nw.HeaderAlign = nstyle.HeaderRight + nw.Mprog = 60 + nw.Mslider = 8 + nw.Mcheck = true + + return nw +} + +// Master Window +func (nw *nucularWindow) nucularWindow(w *nucular.Window) { + //keybindings(w) + mw := w.Master() + + style := mw.Style() + style.NormalWindow.Header.Align = nw.HeaderAlign + if nw.ShowMenu { + nw.nucularMenubar(w) + } + w.Row(30).Dynamic(1) + w.Label(hea,"CC") + //w.Spacing(2) + for _,d := range(dat) { + if w.TreePush(nucular.TreeTab, d.title, true) { + w.Row(20).Dynamic(2) + //w.Row(20).Dynamic(3) + //w.Row(20).Static(100) + for i,_ := range(d.textl){ + w.Label(d.textl[i], "RC") + w.Label(d.textr[i], "LC") + //w.Label("", "LC") + } + + w.TreePop() + } + } + w.Row(30).Static(300, 100, 100) + w.Label("", "LC") + if w.ButtonText("Exit") { + os.Exit(0) + } +} + + +func (nw *nucularWindow) nucularMenubar(w *nucular.Window) { + w.MenubarBegin() + w.Row(25).Static(45, 70, 45, 70, 70) + if w := w.Menu(label.TA("Menu", "CC"), 120, nil); w != nil { + w.Row(25).Dynamic(1) + /*if w.MenuItem(label.TA("Hide", "LC")) { + w.Label("You Wish","LC") + //nw.ShowMenu = false + }*/ + if w.MenuItem(label.TA("About", "LC")) { + nw.showAppAbout(w.Master()) + } + if w.MenuItem(label.TA("Quit", "LC")) { + nw.showQuestion(w.Master()) //,"Do You want to Quit?") { + //os.Exit(0) + //} + } + } + if w := w.Menu(label.TA("Theme", "CC"), 180, nil); w != nil { + w.Row(25).Dynamic(1) + newtheme := nw.Theme + if w.OptionText("Default Theme", newtheme == nstyle.DefaultTheme) { + newtheme = nstyle.DefaultTheme + } + if w.OptionText("White Theme", newtheme == nstyle.WhiteTheme) { + newtheme = nstyle.WhiteTheme + } + if w.OptionText("Red Theme", newtheme == nstyle.RedTheme) { + newtheme = nstyle.RedTheme + } + if w.OptionText("Dark Theme", newtheme == nstyle.DarkTheme) { + newtheme = nstyle.DarkTheme + } + if newtheme != nw.Theme { + nw.Theme = newtheme + w.Master().SetStyle(nstyle.FromTheme(nw.Theme, w.Master().Style().Scaling)) + w.Close() + } + } + w.MenubarEnd() +} + +func (nw *nucularWindow) errorPopup(w *nucular.Window) { + w.Row(25).Dynamic(1) + w.Label("A terrible error has occured", "LC") + w.Row(25).Dynamic(2) + if w.Button(label.T("OK"), false) { + w.Close() + } + if w.Button(label.T("Cancel"), false) { + w.Close() + } +} + +func (nw *nucularWindow) questionPopup(w *nucular.Window) { + w.Row(25).Dynamic(1) + w.Label("Are You Sure?", "LC") + w.Row(25).Dynamic(2) + if w.Button(label.T("OK"), false) { + os.Exit(0) + } + if w.Button(label.T("Cancel"), false) { + w.Close() + } +} + +func (nw *nucularWindow) aboutPopup(w *nucular.Window) { + w.Row(20).Dynamic(1) + w.Label("Fenestra", "LC") + w.Row(40).Dynamic(1) + w.LabelWrap("A viewer for my text based Cheatsheets.") + w.Row(15).Dynamic(1) + w.Label("Usind Nucular by Alessandro Arzilli", "LC") + w.Label("based on Nuklear by Micha Mettke", "LC") + + if w.Button(label.T("OK"), false) { + w.Close() + } +} + +func (nw *nucularWindow) showAppAbout(mw nucular.MasterWindow) { + var wf nucular.WindowFlags + + if nw.Border { + wf |= nucular.WindowBorder + } + if nw.Resize { + wf |= nucular.WindowScalable + } + if nw.Movable { + wf |= nucular.WindowMovable + } + if nw.NoScrollbar { + wf |= nucular.WindowNoScrollbar + } + if nw.Close { + wf |= nucular.WindowClosable + } + if nw.Titlebar { + wf |= nucular.WindowTitle + } + mw.PopupOpen("About", wf, rect.Rect{20, 100, 300, 190}, true, nw.aboutPopup) +} + +func (nw *nucularWindow) showQuestion(mw nucular.MasterWindow) { + var wf nucular.WindowFlags + + if nw.Border { + wf |= nucular.WindowBorder + } + if nw.Resize { + wf |= nucular.WindowScalable + } + if nw.Movable { + wf |= nucular.WindowMovable + } + if nw.NoScrollbar { + wf |= nucular.WindowNoScrollbar + } + if nw.Close { + wf |= nucular.WindowClosable + } + if nw.Titlebar { + wf |= nucular.WindowTitle + } + mw.PopupOpen("QUIT", wf, rect.Rect{20, 100, 300, 190}, true, nw.questionPopup) +} -- cgit v1.2.3