Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
84 lines (72 loc) · 1.67 KB
/
Copy pathmain.go
File metadata and controls
84 lines (72 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"os"
ui "github.com/gizak/termui"
)
const statusBarHeight = 1
const categoriesHeight = 1
func logViewHeight(termHeight int) int {
return termHeight - categoriesHeight - statusBarHeight
}
type resize struct {
height int
width int
}
func (action resize) Apply(state AppState) AppState {
state.termHeight = action.height
state.termWidth = action.width
return state
}
// Render the application as a function of state
func Render(state AppState) {
mainColumns := state.LogViews.display(state)
if state.showMods {
filterColumn := state.modifiers.display(state)
mainColumns = append(mainColumns, filterColumn)
}
mainRow := ui.NewRow(mainColumns...)
ui.Body.Rows = []*ui.Row{
state.displayFileBar(),
mainRow,
state.StatusBar.display(state),
}
ui.Body.Width = ui.TermWidth()
ui.Body.Align()
ui.Render(ui.Body)
if state.CurrentMode == selectCategory {
renderSelectCategoryModal(state)
}
}
func initUI() {
err := ui.Init()
if err != nil {
panic(err)
}
}
func main() {
fileNames := os.Args[1:]
if len(fileNames) == 0 {
fmt.Printf("usage: lumberjack logfile1 logfile2 ...")
return
}
initUI()
defer ui.Close()
store := NewStore()
state := NewAppState(fileNames, ui.TermHeight(), ui.TermWidth())
addWatchers(fileNames, store.Actions)
go store.ReduceLoop(state)
ui.Handle("/sys/kbd/C-c", func(ui.Event) {
ui.StopLoop()
})
ui.Handle("/sys/kbd", func(e ui.Event) {
key := e.Data.(ui.EvtKbd).KeyStr
store.Actions <- KeyPress{Key: key}
})
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
wndEvent := e.Data.(ui.EvtWnd)
// Force rerender
store.Actions <- resize{height: wndEvent.Height, width: wndEvent.Width}
})
ui.Loop()
}