mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 11:57:50 +02:00
Add handling to adjust the vertical size on the fly too
This commit is contained in:
parent
085d2a917f
commit
6983b04c47
@ -244,6 +244,10 @@ func calculateColumnWidths(rows []table.Row) []int {
|
|||||||
return neededColumnWidth
|
return neededColumnWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTerminalSize() (int, int, error) {
|
||||||
|
return term.GetSize(2)
|
||||||
|
}
|
||||||
|
|
||||||
var bigQueryResults []table.Row
|
var bigQueryResults []table.Row
|
||||||
|
|
||||||
func makeTableColumns(ctx *context.Context, columnNames []string, rows []table.Row) ([]table.Column, error) {
|
func makeTableColumns(ctx *context.Context, columnNames []string, rows []table.Row) ([]table.Column, error) {
|
||||||
@ -266,7 +270,7 @@ func makeTableColumns(ctx *context.Context, columnNames []string, rows []table.R
|
|||||||
maximumColumnWidths := calculateColumnWidths(bigQueryResults)
|
maximumColumnWidths := calculateColumnWidths(bigQueryResults)
|
||||||
|
|
||||||
// Get the actual terminal width. If we're below this, opportunistically add some padding aiming for the maximum column widths
|
// Get the actual terminal width. If we're below this, opportunistically add some padding aiming for the maximum column widths
|
||||||
terminalWidth, _, err := term.GetSize(2)
|
terminalWidth, _, err := getTerminalSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get terminal size: %v", err)
|
return nil, fmt.Errorf("failed to get terminal size: %v", err)
|
||||||
}
|
}
|
||||||
@ -311,6 +315,12 @@ func max(a, b int) int {
|
|||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
func makeTable(ctx *context.Context, rows []table.Row) (table.Model, error) {
|
func makeTable(ctx *context.Context, rows []table.Row) (table.Model, error) {
|
||||||
config := hctx.GetConf(ctx)
|
config := hctx.GetConf(ctx)
|
||||||
@ -344,11 +354,17 @@ func makeTable(ctx *context.Context, rows []table.Row) (table.Model, error) {
|
|||||||
key.WithHelp("end", "go to end"),
|
key.WithHelp("end", "go to end"),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
_, terminalHeight, err := getTerminalSize()
|
||||||
|
if err != nil {
|
||||||
|
return table.Model{}, err
|
||||||
|
}
|
||||||
|
// panic(terminalHeight)
|
||||||
|
tableHeight := min(TABLE_HEIGHT, terminalHeight-10)
|
||||||
t := table.New(
|
t := table.New(
|
||||||
table.WithColumns(columns),
|
table.WithColumns(columns),
|
||||||
table.WithRows(rows),
|
table.WithRows(rows),
|
||||||
table.WithFocused(true),
|
table.WithFocused(true),
|
||||||
table.WithHeight(TABLE_HEIGHT),
|
table.WithHeight(tableHeight),
|
||||||
table.WithKeyMap(km),
|
table.WithKeyMap(km),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user