Skip to content

Commit

Permalink
Have SortIndex letter highlighted by default
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Feb 10, 2023
1 parent c07057a commit 486e946
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
7 changes: 5 additions & 2 deletions internal/color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func Colorize(s string, c Paint) string {
return fmt.Sprintf(colorFmt, c, s)
}

func ColorizeAt(s string, idx int, color string) string {
if len(s) <= idx {
func ColorizeAt(s string, idx int, color string, underscore bool) string {
if idx < 0 || len(s) <= idx {
return s
}
//colr := color.New(c).FprintfFunc()
Expand All @@ -44,6 +44,9 @@ func ColorizeAt(s string, idx int, color string) string {
left := string(chrs[:idx])

mid := fmt.Sprintf("[-:-:-][%s::b]%s[-:-:-]", color, string(chrs[idx]))
if underscore {
mid = fmt.Sprintf("[-:-:-][%s::bu]%s[-:-:-]", color, string(chrs[idx]))
}
right := string(chrs[idx+1:])
return fmt.Sprintf("%s%s%s", left, mid, right)
}
Expand Down
1 change: 1 addition & 0 deletions internal/ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (t *Table) buildRow(r int, re, ore render.RowEvent, h render.Header) {
// AddHeaderCell configures a table cell header.
func (t *Table) AddHeaderCell(col int, h render.HeaderColumn) {
sort := h.Name == t.sortCol.name
//c := tview.NewTableCell(sortIndicator(sort, t.sortCol.asc, h))
c := tview.NewTableCell(sortIndicator(sort, t.sortCol.asc, h))
c.SetTextColor(tcell.ColorBeige)
c.SetAttributes(tcell.AttrBold)
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/table_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func TrimCell(tv *SelectTable, row, col int) string {

func sortIndicator(sort, asc bool, hc render.HeaderColumn) string {
if !sort {
return hc.Name
return color.ColorizeAt(hc.Name, hc.SortIndicatorIdx, "wheat", true)
}

order := descIndicator
if asc {
order = ascIndicator
}
return fmt.Sprintf("%s%s", color.ColorizeAt(hc.Name, hc.SortIndicatorIdx, "red"), color.ColorizeAt(order, 0, "green"))
return fmt.Sprintf("%s%s", color.ColorizeAt(hc.Name, hc.SortIndicatorIdx, "red", true), color.ColorizeAt(order, 0, "green", false))
}
10 changes: 5 additions & 5 deletions internal/view/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func NewEC2(resource string) ResourceViewer {

func (e *EC2) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftI: ui.NewKeyAction("Sort Instance-Id", e.GetTable().SortColCmd("Instance-Id", true), false),
ui.KeyShiftS: ui.NewKeyAction("Sort Instance-State", e.GetTable().SortColCmd("Instance-State", true), false),
ui.KeyShiftT: ui.NewKeyAction("Sort Instance-Type", e.GetTable().SortColCmd("Instance-Type", true), false),
ui.KeyShiftL: ui.NewKeyAction("Sort Launch-Time", e.GetTable().SortColCmd("Launch-Time", true), false),
ui.KeyShiftM: ui.NewKeyAction("Sort Monitoring-State", e.GetTable().SortColCmd("Monitoring-State", true), false),
ui.KeyShiftI: ui.NewKeyAction("Sort Instance-Id", e.GetTable().SortColCmd("Instance-Id", true), true),
ui.KeyShiftS: ui.NewKeyAction("Sort Instance-State", e.GetTable().SortColCmd("Instance-State", true), true),
ui.KeyShiftT: ui.NewKeyAction("Sort Instance-Type", e.GetTable().SortColCmd("Instance-Type", true), true),
ui.KeyShiftL: ui.NewKeyAction("Sort Launch-Time", e.GetTable().SortColCmd("Launch-Time", true), true),
ui.KeyShiftM: ui.NewKeyAction("Sort Monitoring-State", e.GetTable().SortColCmd("Monitoring-State", true), true),
ui.KeyShiftP: ui.NewKeyAction("Sort Public-DNS", e.GetTable().SortColCmd("Public-DNS", true), false),
tcell.KeyEscape: ui.NewKeyAction("Back", e.App().PrevCmd, false),
tcell.KeyEnter: ui.NewKeyAction("View", e.enterCmd, false),
Expand Down
7 changes: 2 additions & 5 deletions internal/view/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ func (t *Table) importAsCSV(evt *tcell.EventKey) *tcell.EventKey {
var row []string
for j := 0; j < colCount; j++ {
text := t.GetCell(i, j).Text
if strings.Contains(text, "↑") || strings.Contains(text, "↓") {
text = decolorize(text)
text = text[:len(text)-3]
}
text = decolorize(text)
row = append(row, text)
}
tableData = append(tableData, row)
Expand Down Expand Up @@ -150,6 +147,6 @@ func (t *Table) importAsCSV(evt *tcell.EventKey) *tcell.EventKey {
}

func decolorize(input string) string {
re := regexp.MustCompile("\\[.*?\\]")
re := regexp.MustCompile(`\[.*?\]|\^`)
return re.ReplaceAllString(input, "")
}

0 comments on commit 486e946

Please sign in to comment.