summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.txt56
-rw-r--r--main.go77
-rw-r--r--nucuwin.go221
3 files changed, 354 insertions, 0 deletions
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
+<Win> - P -- Launch Dmenu
+<Win> - S -- Launch Synergy
+<Win> - F -- Launch Nautilus
+<Win><Shift> - <Enter> -- Launch Terminal
+<Win><Shift> - C -- Kill Focused Window
+
+##Layout
+<Win> - <Space> -- Rotate through Layouts
+<Win><Shift> - <Space> -- Reset Layout of Current Workspace
+<Win> - N -- Resize Window to Correct size
+<Win> - B -- Toggle Strouts (Fullestscreen)
+<Win><Ctrl> - B -- Toggle StatBar
+<Win> - H -- Shrink Master Area
+<Win> - L -- Expand Master Area
+<Win> - T -- Push Floater back to Tiling
+<Win> - <Left Mouse> -- Make Window Float and Move
+<Win> - <Right Mouse> -- Make Window Float and Resize
+<Win> - , -- Increase Windows in Master Area
+<Win> - . -- Decrease Windows in Master Area
+<Win> - A -- Mirror Shrink
+<Win> - Y -- Mirror Expand
+
+##Focus and Order
+<Win> - <Tab> -- Focus on Next Window
+<Win><Shift> - <Tab> -- Focus on Previous Window
+<Win> - J -- Focus on Next Window
+<Win> - K -- Focus on Previous Window
+<Win> - M -- Focus on Master Window
+<Win><Shift> - J -- Swap Focused Window with Next
+<Win><Shift> - K -- Swap Focused Window with Previous
+<Win><Return> -- Swap Focused with Master
+<Win> - U -- Focus on Urgent Window
+
+##Workspaces & Screens
+<Win> [1-0,-,+] -- Switch to Workspace N
+<Win><Shift> [1-0,-,+] -- Move Window to Workspace N
+<Win> [w,e,r] -- Switch to Screen 1,2 or 3
+<Win><Shift> [w,e,r] -- Move Window to Screen 1,2 or 3
+<Win> [Arrow Keys] -- Move on Workspace Pattern
+<Win> - D -- Toggle Single and Multiscreen
+
+##Login
+<Win> - Q -- Reload Xmonad
+<Win> - Ö -- Lock Screen
+<Win><Shift> - Q -- Quit Xmonad and Logout User
+
+##System
+<Print> -- Screenshot of current Workspace
+<Win> - <Print> -- Screenshot of All Workspaces
+<Win><Ctrl> - <Print> -- Screenshot of current Window
+<Win> - Ä -- 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)
+}