Commit
+77 -68 +/-3 browse
1 | diff --git a/go.mod b/go.mod |
2 | index 7ba0c9f..28a4dd2 100644 |
3 | --- a/go.mod |
4 | +++ b/go.mod |
5 | @@ -6,13 +6,14 @@ require ( |
6 | github.com/0xAX/notificator v0.0.0-20181105090803-d81462e38c21 |
7 | github.com/fatih/color v1.7.0 |
8 | github.com/gizak/termui v2.3.0+incompatible |
9 | + github.com/gizak/termui/v3 v3.1.0 // indirect |
10 | github.com/jawher/mow.cli v1.0.4 |
11 | github.com/maruel/panicparse v0.0.0-20180806203336-f20d4c4d746f |
12 | github.com/mattn/go-colorable v0.0.9 |
13 | github.com/mattn/go-isatty v0.0.4 |
14 | - github.com/mattn/go-runewidth v0.0.4 |
15 | + github.com/mattn/go-runewidth v0.0.13 |
16 | github.com/mattn/go-sqlite3 v1.10.0 |
17 | - github.com/mitchellh/go-wordwrap v1.0.0 |
18 | - github.com/nsf/termbox-go v0.0.0-20190104133558-0938b5187e61 |
19 | + github.com/mitchellh/go-wordwrap v1.0.1 |
20 | + github.com/nsf/termbox-go v1.1.1 |
21 | golang.org/x/sys v0.0.0-20190116161447-11f53e031339 |
22 | ) |
23 | diff --git a/go.sum b/go.sum |
24 | index 6f8595e..398888d 100644 |
25 | --- a/go.sum |
26 | +++ b/go.sum |
27 | @@ -4,6 +4,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= |
28 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= |
29 | github.com/gizak/termui v2.3.0+incompatible h1:S8wJoNumYfc/rR5UezUM4HsPEo3RJh0LKdiuDWQpjqw= |
30 | github.com/gizak/termui v2.3.0+incompatible/go.mod h1:PkJoWUt/zacQKysNfQtcw1RW+eK2SxkieVBtl+4ovLA= |
31 | + github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc= |
32 | + github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= |
33 | github.com/jawher/mow.cli v1.0.4 h1:hKjm95J7foZ2ngT8tGb15Aq9rj751R7IUDjG+5e3cGA= |
34 | github.com/jawher/mow.cli v1.0.4/go.mod h1:5hQj2V8g+qYmLUVWqu4Wuja1pI57M83EChYLVZ0sMKk= |
35 | github.com/maruel/panicparse v0.0.0-20180806203336-f20d4c4d746f h1:qiwX3rjQBtp68F8LsKgURRQiFCWiNdN8EB9b+EMLv1k= |
36 | @@ -12,12 +14,24 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU |
37 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= |
38 | github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= |
39 | github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= |
40 | + github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= |
41 | github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= |
42 | github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= |
43 | + github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= |
44 | + github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= |
45 | + github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= |
46 | github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= |
47 | github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= |
48 | + github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= |
49 | github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= |
50 | github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= |
51 | + github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= |
52 | + github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= |
53 | github.com/nsf/termbox-go v0.0.0-20190104133558-0938b5187e61 h1:pEzZYac/uQ4cgaN1Q/UYZg+ZtCSWz2HQ3rvl8MeN9MA= |
54 | github.com/nsf/termbox-go v0.0.0-20190104133558-0938b5187e61/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= |
55 | + github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= |
56 | + github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY= |
57 | + github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo= |
58 | + github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= |
59 | + github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= |
60 | golang.org/x/sys v0.0.0-20190116161447-11f53e031339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
61 | diff --git a/pkg/internal/ui.go b/pkg/internal/ui.go |
62 | index 4aa5f99..b5f9475 100644 |
63 | --- a/pkg/internal/ui.go |
64 | +++ b/pkg/internal/ui.go |
65 | @@ -2,15 +2,16 @@ package pomo |
66 | |
67 | import ( |
68 | "fmt" |
69 | + "time" |
70 | |
71 | - "github.com/gizak/termui" |
72 | + ui "github.com/gizak/termui/v3" |
73 | + "github.com/gizak/termui/v3/widgets" |
74 | ) |
75 | |
76 | - func render(wheel *Wheel, status *Status) termui.GridBufferer { |
77 | - var text string |
78 | + func setContent(wheel *Wheel, status *Status, par *widgets.Paragraph) { |
79 | switch status.State { |
80 | case RUNNING: |
81 | - text = fmt.Sprintf( |
82 | + par.Text = fmt.Sprintf( |
83 | `[%d/%d] Pomodoros completed |
84 | |
85 | %s %s remaining |
86 | @@ -24,15 +25,15 @@ func render(wheel *Wheel, status *Status) termui.GridBufferer { |
87 | status.Remaining, |
88 | ) |
89 | case BREAKING: |
90 | - text = `It is time to take a break! |
91 | + par.Text = `It is time to take a break! |
92 | |
93 | - Once you are ready, press [enter] |
94 | + Once you are ready, press [enter] |
95 | to begin the next Pomodoro. |
96 | |
97 | [q] - quit [p] - pause |
98 | ` |
99 | case PAUSED: |
100 | - text = `Pomo is suspended. |
101 | + par.Text = `Pomo is suspended. |
102 | |
103 | Press [p] to continue. |
104 | |
105 | @@ -40,84 +41,77 @@ func render(wheel *Wheel, status *Status) termui.GridBufferer { |
106 | [q] - quit [p] - unpause |
107 | ` |
108 | case COMPLETE: |
109 | - text = `This session has concluded. |
110 | - |
111 | + par.Text = `This session has concluded. |
112 | + |
113 | Press [q] to exit. |
114 | |
115 | |
116 | [q] - quit |
117 | ` |
118 | } |
119 | - par := termui.NewPar(text) |
120 | - par.Height = 8 |
121 | - par.BorderLabel = fmt.Sprintf("Pomo - %s", status.State) |
122 | - par.BorderLabelFg = termui.ColorWhite |
123 | - par.BorderFg = termui.ColorRed |
124 | + par.Title = fmt.Sprintf("Pomo - %s", status.State) |
125 | + par.TitleStyle.Fg = ui.ColorWhite |
126 | + par.BorderStyle.Fg = ui.ColorRed |
127 | if status.State == RUNNING { |
128 | - par.BorderFg = termui.ColorGreen |
129 | + par.BorderStyle.Fg = ui.ColorGreen |
130 | } |
131 | - return par |
132 | - } |
133 | - |
134 | - func newBlk() termui.GridBufferer { |
135 | - blk := termui.NewBlock() |
136 | - blk.Height = termui.TermHeight() / 3 |
137 | - blk.Border = false |
138 | - return blk |
139 | - } |
140 | - |
141 | - func centered(part termui.GridBufferer) *termui.Grid { |
142 | - grid := termui.NewGrid( |
143 | - termui.NewRow( |
144 | - termui.NewCol(12, 0, newBlk()), |
145 | - ), |
146 | - termui.NewRow( |
147 | - termui.NewCol(3, 0, newBlk()), |
148 | - termui.NewCol(6, 0, part), |
149 | - termui.NewCol(3, 0, newBlk()), |
150 | - ), |
151 | - termui.NewRow( |
152 | - termui.NewCol(12, 0, newBlk()), |
153 | - ), |
154 | - ) |
155 | - grid.BgColor = termui.ThemeAttr("bg") |
156 | - grid.Width = termui.TermWidth() |
157 | - grid.Align() |
158 | - return grid |
159 | } |
160 | |
161 | func StartUI(runner *TaskRunner) { |
162 | - err := termui.Init() |
163 | + err := ui.Init() |
164 | if err != nil { |
165 | panic(err) |
166 | } |
167 | - wheel := Wheel(0) |
168 | |
169 | - defer termui.Close() |
170 | + ticker := time.NewTicker(250 * time.Millisecond) |
171 | |
172 | - termui.Render(centered(render(&wheel, runner.Status()))) |
173 | + defer ui.Close() |
174 | |
175 | - termui.Handle("/timer/1s", func(termui.Event) { |
176 | - termui.Render(centered(render(&wheel, runner.Status()))) |
177 | - }) |
178 | + wheel := Wheel(0) |
179 | + |
180 | + par := widgets.NewParagraph() |
181 | + |
182 | + resize := func() { |
183 | + termWidth, termHeight := ui.TerminalDimensions() |
184 | |
185 | - termui.Handle("/sys/wnd/resize", func(termui.Event) { |
186 | - termui.Render(centered(render(&wheel, runner.Status()))) |
187 | - }) |
188 | + x1 := (termWidth - 50) / 2 |
189 | + x2 := x1 + 50 |
190 | + y1 := (termHeight - 8) / 2 |
191 | + y2 := y1 + 8 |
192 | |
193 | - termui.Handle("/sys/kbd/<enter>", func(termui.Event) { |
194 | - runner.Toggle() |
195 | - termui.Render(centered(render(&wheel, runner.Status()))) |
196 | - }) |
197 | + par.SetRect(x1, y1, x2, y2) |
198 | + ui.Clear() |
199 | + } |
200 | |
201 | - termui.Handle("/sys/kbd/p", func(termui.Event) { |
202 | - runner.Pause() |
203 | - termui.Render(centered(render(&wheel, runner.Status()))) |
204 | - }) |
205 | + render := func() { |
206 | + setContent(&wheel, runner.Status(), par) |
207 | + ui.Render(par) |
208 | + } |
209 | |
210 | - termui.Handle("/sys/kbd/q", func(termui.Event) { |
211 | - termui.StopLoop() |
212 | - }) |
213 | + resize() |
214 | + render() |
215 | + |
216 | + events := ui.PollEvents() |
217 | + |
218 | + for { |
219 | + select { |
220 | + case e := <-events: |
221 | + switch e.ID { |
222 | + case "q", "<C-c>": |
223 | + return |
224 | + case "<Resize>": |
225 | + resize() |
226 | + render() |
227 | + case "<Enter>": |
228 | + runner.Toggle() |
229 | + render() |
230 | + case "p": |
231 | + runner.Pause() |
232 | + render() |
233 | + } |
234 | + case <-ticker.C: |
235 | + render() |
236 | + } |
237 | + } |
238 | |
239 | - termui.Loop() |
240 | } |