Skip to content

Commit e23dc2c

Browse files
committed
feat: allow setting of fixed columns in the list of issues
1 parent 999ddad commit e23dc2c

File tree

4 files changed

+59
-15
lines changed

4 files changed

+59
-15
lines changed

Diff for: internal/cmd/issue/list/list.go

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func loadList(cmd *cobra.Command) {
142142
return []string{}
143143
}(),
144144
TableStyle: cmdutil.GetTUIStyleConfig(),
145+
CustomKeys: viper.GetStringMap("custom_keys.issues"),
145146
},
146147
}
147148

Diff for: internal/view/helper.go

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"os"
7+
"os/exec"
78
"strings"
89
"text/tabwriter"
910
"time"
@@ -115,6 +116,24 @@ func jiraURLFromTuiData(server string, r int, d interface{}) string {
115116
return fmt.Sprintf("%s/browse/%s", server, issueKeyFromTuiData(r, d))
116117
}
117118

119+
func runInSh(command string) {
120+
cmd := exec.Command("sh", "-c", command)
121+
_ = cmd.Run()
122+
}
123+
124+
func customKeyFunc(row, _ int, data interface{}, command string) {
125+
i := issueKeyFromTuiData(row, data)
126+
expandedCommand := strings.ReplaceAll(command, "%KEY%", i)
127+
if strings.HasPrefix(expandedCommand, "&") {
128+
go func() {
129+
expandedCommand = strings.TrimPrefix(expandedCommand, "&")
130+
runInSh(expandedCommand)
131+
}()
132+
} else {
133+
runInSh(expandedCommand)
134+
}
135+
}
136+
118137
func navigate(server string) tui.SelectedFunc {
119138
return func(r, c int, d interface{}) {
120139
_ = browser.Browse(jiraURLFromTuiData(server, r, d))

Diff for: internal/view/issues.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type DisplayFormat struct {
2121
Columns []string
2222
FixedColumns uint
2323
TableStyle tui.TableStyle
24+
CustomKeys map[string]interface{}
2425
}
2526

2627
// IssueList is a list view for issues.
@@ -52,6 +53,7 @@ func (l *IssueList) Render() error {
5253
}
5354

5455
view := tui.NewTable(
56+
tui.WithCustomKeyFunc(customKeyFunc, l.Display.CustomKeys),
5557
tui.WithTableStyle(l.Display.TableStyle),
5658
tui.WithTableFooterText(l.FooterText),
5759
tui.WithSelectedFunc(navigate(l.Server)),

Diff for: pkg/tui/table.go

+37-15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type CopyFunc func(row, column int, data interface{})
3030
// CopyKeyFunc is fired when a user press 'CTRL+K' character in the table cell.
3131
type CopyKeyFunc func(row, column int, data interface{})
3232

33+
// CustomKeyFunc is fired when one of custom keys is pressed in the table cell.
34+
type CustomKeyFunc func(row, column int, data interface{}, command string)
35+
3336
// TableData is the data to be displayed in a table.
3437
type TableData [][]string
3538

@@ -42,21 +45,23 @@ type TableStyle struct {
4245

4346
// Table is a table layout.
4447
type Table struct {
45-
screen *Screen
46-
painter *tview.Pages
47-
view *tview.Table
48-
footer *tview.TextView
49-
style TableStyle
50-
data TableData
51-
colPad uint
52-
colFixed uint
53-
maxColWidth uint
54-
footerText string
55-
selectedFunc SelectedFunc
56-
viewModeFunc ViewModeFunc
57-
refreshFunc RefreshFunc
58-
copyFunc CopyFunc
59-
copyKeyFunc CopyKeyFunc
48+
screen *Screen
49+
painter *tview.Pages
50+
view *tview.Table
51+
footer *tview.TextView
52+
style TableStyle
53+
data TableData
54+
colPad uint
55+
colFixed uint
56+
maxColWidth uint
57+
footerText string
58+
selectedFunc SelectedFunc
59+
viewModeFunc ViewModeFunc
60+
customKeys map[string]interface{}
61+
customKeyFunc CustomKeyFunc
62+
refreshFunc RefreshFunc
63+
copyFunc CopyFunc
64+
copyKeyFunc CopyKeyFunc
6065
}
6166

6267
// TableOption is a functional option to wrap table properties.
@@ -121,6 +126,14 @@ func WithViewModeFunc(fn ViewModeFunc) TableOption {
121126
}
122127
}
123128

129+
// WithCustomKeyFunc sets a func that is triggered when one of custom keys is pressed.
130+
func WithCustomKeyFunc(fn CustomKeyFunc, keys map[string]interface{}) TableOption {
131+
return func(t *Table) {
132+
t.customKeyFunc = fn
133+
t.customKeys = keys
134+
}
135+
}
136+
124137
// WithRefreshFunc sets a func that is triggered when a user press 'CTRL+R' or 'F5'.
125138
func WithRefreshFunc(fn RefreshFunc) TableOption {
126139
return func(t *Table) {
@@ -232,6 +245,15 @@ func (t *Table) initTable() {
232245
// Refresh the screen.
233246
t.screen.Draw()
234247
}()
248+
default:
249+
if t.customKeyFunc != nil && t.customKeys != nil {
250+
for k, command := range t.customKeys {
251+
if string(ev.Rune()) == k {
252+
r, c := t.view.GetSelection()
253+
t.customKeyFunc(r, c, t.data, command.(string))
254+
}
255+
}
256+
}
235257
}
236258
}
237259
return ev

0 commit comments

Comments
 (0)