From 2452c88fd2d59fad69f152d3e60a94b028f5ef56 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 18 Aug 2023 18:52:40 +0200 Subject: [PATCH] Improved layout --- README.md | 20 +++++++++++--------- clock/clock.go | 12 +++--------- core/Process.go | 4 +++- editor/editor.go | 2 +- empty/empty.go | 13 +++++++++++++ main.go | 16 ++++++++++++---- osinfo/osinfo.go | 24 ------------------------ 7 files changed, 43 insertions(+), 48 deletions(-) create mode 100644 empty/empty.go delete mode 100644 osinfo/osinfo.go diff --git a/README.md b/README.md index 053cd73..06cf7c9 100644 --- a/README.md +++ b/README.md @@ -2,28 +2,30 @@ Dashboard for my terminal. -## Usage +## Examples -- Run your terminal in fullscreen -- Set the terminal opacity to 50% -- Start `dash` +Transparent: + +![dash transparent](https://i.imgur.com/hc7tJYT.png) + +Opaque: + +![dash opaque](https://i.imgur.com/8rxHhDE.png) ## Config The configuration is a normal text file living in `~/.config/dash/`. -You can use it to take notes or display the output of shell commands via the `{command args}` syntax. - -The output can be piped to other commands, e.g. `{pacman -Q | wc -l} packages installed`. +You can use it to take plain old notes or display the output of shell commands via the `{command args}` syntax. ## Terminals ### alacritty -If you're using alacritty you can set the opacity for a single instance via: +You can set the opacity for a single window via: ```sh alacritty msg config window.opacity=0.5 ``` -This will make your dashboard transparent but leaves the other windows at full transparency. +This will make your dashboard transparent but leaves the other windows at full opacity. diff --git a/clock/clock.go b/clock/clock.go index 6c83c1c..f6daacf 100644 --- a/clock/clock.go +++ b/clock/clock.go @@ -7,26 +7,20 @@ import ( "github.com/rivo/tview" ) -const ( - interval = 1 * time.Second - format = "15:04:05" -) - -func New(app *tview.Application) *tview.TextView { +func New(format string, interval time.Duration) *tview.TextView { view := tview.NewTextView() view.SetTextAlign(tview.AlignCenter) view.SetBackgroundColor(tcell.ColorDefault) view.SetText(time.Now().Format(format)) view.SetBorderPadding(1, 1, 1, 1) - go refresh(app, view) + go refresh(view, format, interval) return view } -func refresh(app *tview.Application, view *tview.TextView) { +func refresh(view *tview.TextView, format string, interval time.Duration) { tick := time.NewTicker(interval) for range tick.C { view.SetText(time.Now().Format(format)) - app.Draw() } } diff --git a/core/Process.go b/core/Process.go index 671270b..b1cbe5d 100644 --- a/core/Process.go +++ b/core/Process.go @@ -4,6 +4,8 @@ import ( "os/exec" "regexp" "strings" + + "github.com/rivo/tview" ) var ( @@ -21,7 +23,7 @@ func Process(source string) string { return err.Error() } - return strings.Trim(string(output), "\n") + return tview.TranslateANSI(strings.Trim(string(output), "\n")) }) return source diff --git a/editor/editor.go b/editor/editor.go index 8a740b8..c0cb397 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -16,7 +16,7 @@ type Editor struct { IsDirty bool } -func New(app *tview.Application, filePath string) *Editor { +func New(filePath string) *Editor { e := &Editor{ FilePath: filePath, } diff --git a/empty/empty.go b/empty/empty.go new file mode 100644 index 0000000..b1635ac --- /dev/null +++ b/empty/empty.go @@ -0,0 +1,13 @@ +package empty + +import ( + "github.com/gdamore/tcell/v2" + "github.com/rivo/tview" +) + +func New() *tview.Box { + view := tview.NewBox() + view.SetBackgroundColor(tcell.ColorDefault) + view.SetBorderPadding(1, 1, 1, 1) + return view +} diff --git a/main.go b/main.go index 829f3ef..1609e0e 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,11 @@ package main import ( "os" "path/filepath" + "time" "git.akyoto.dev/cli/dash/clock" "git.akyoto.dev/cli/dash/core" "git.akyoto.dev/cli/dash/editor" - "git.akyoto.dev/cli/dash/osinfo" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -28,9 +28,9 @@ func main() { panic(err) } - header := clock.New(app) - main := editor.New(app, filepath.Join(dataDir, "main")) - footer := osinfo.New(app) + header := clock.New("15:04:05", time.Second) + main := editor.New(filepath.Join(dataDir, "main")) + footer := clock.New("2006-01-02", time.Hour) grid.AddItem(header, 0, 0, 1, 3, 0, 0, false) grid.AddItem(main.Pages, 1, 1, 1, 1, 0, 0, false) @@ -40,6 +40,14 @@ func main() { app.SetRoot(grid, true) app.SetFocus(main.Pages) + go func() { + tick := time.NewTicker(time.Second) + + for range tick.C { + app.Draw() + } + }() + err = app.Run() if err != nil { diff --git a/osinfo/osinfo.go b/osinfo/osinfo.go deleted file mode 100644 index 10e56c7..0000000 --- a/osinfo/osinfo.go +++ /dev/null @@ -1,24 +0,0 @@ -package osinfo - -import ( - "os/exec" - "strings" - - "github.com/gdamore/tcell/v2" - "github.com/rivo/tview" -) - -func New(app *tview.Application) *tview.TextView { - view := tview.NewTextView() - view.SetTextAlign(tview.AlignCenter) - view.SetBackgroundColor(tcell.ColorDefault) - view.SetBorderPadding(1, 1, 1, 1) - - out, _ := exec.Command("lsb_release", "-sd").Output() - distro := string(out) - distro = strings.TrimSpace(distro) - distro = strings.Trim(distro, "\"") - view.SetText(distro) - - return view -}