diff options
author | Daniel Milde <daniel@milde.cz> | 2022-09-06 23:56:48 +0200 |
---|---|---|
committer | Daniel Milde <daniel@milde.cz> | 2022-09-07 00:04:05 +0200 |
commit | 083da816b1534d7a2d6297cc171155cc5130b6e3 (patch) | |
tree | 6a8de3d14eb04818cf2af15ee3295e4ddc5dc3fd /tui/mouse.go | |
parent | e342407b94e791c1745721f6f08b15b23a6ed57c (diff) |
feat: initial mouse support
closes #163
Diffstat (limited to 'tui/mouse.go')
-rw-r--r-- | tui/mouse.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tui/mouse.go b/tui/mouse.go new file mode 100644 index 0000000..18ef8b3 --- /dev/null +++ b/tui/mouse.go @@ -0,0 +1,42 @@ +package tui + +import ( + "github.com/dundee/gdu/v5/pkg/fs" + "github.com/gdamore/tcell/v2" + "github.com/rivo/tview" +) + +func (ui *UI) onMouse(event *tcell.EventMouse, action tview.MouseAction) (*tcell.EventMouse, tview.MouseAction) { + if event == nil { + return nil, action + } + + switch action { + case tview.MouseLeftDoubleClick: + row, column := ui.table.GetSelection() + if ui.currentDirPath != ui.topDirPath && row == 0 { + ui.handleLeft() + } else { + selectedFile := ui.table.GetCell(row, column).GetReference().(fs.Item) + if selectedFile.IsDir() { + ui.handleRight() + } else { + ui.showFile() + } + } + return nil, action + case tview.MouseScrollUp: + fallthrough + case tview.MouseScrollDown: + row, column := ui.table.GetSelection() + if action == tview.MouseScrollUp && row > 0 { + row-- + } else if action == tview.MouseScrollDown && row+1 < ui.table.GetRowCount() { + row++ + } + ui.table.Select(row, column) + return nil, action + } + + return event, action +} |