Skip to content

Commit

Permalink
优化content展示
Browse files Browse the repository at this point in the history
  • Loading branch information
林通 committed Aug 13, 2020
1 parent 2f3c3d1 commit f665a83
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 36 deletions.
80 changes: 49 additions & 31 deletions content.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (

var maxLineNum = 80

var maxContentLineSize = 30
var maxContentLineSize = 1
var displayLineSize = 30

type Entry struct {
command bytes.Buffer
Expand Down Expand Up @@ -233,15 +234,22 @@ func (c *Content)contentDownPage() {
return
}

c.contentEndIdx += maxContentLineSize
c.contentStartIdx += maxContentLineSize
if c.contentEndIdx > len(lines) {
c.contentEndIdx = len(lines)
oldStart := c.contentStartIdx
oldEnd := c.contentEndIdx

// 满足往下走的条件
if c.contentStartIdx < len(lines) && c.contentStartIdx + maxContentLineSize < len(lines) &&
c.contentEndIdx < len(lines) && c.contentEndIdx + maxContentLineSize < len(lines) {
c.contentStartIdx += maxContentLineSize
c.contentEndIdx += maxContentLineSize
}

if c.contentStartIdx > len(lines) {
c.contentStartIdx = len(lines)
if c.contentStartIdx >= c.contentEndIdx {
c.contentStartIdx = oldStart
c.contentEndIdx = oldEnd
}


c.contentWidget.Text = c.decorateText(idx, c.contentStartIdx, c.contentEndIdx)
}

Expand All @@ -250,13 +258,17 @@ func (c *Content)contentUpPage() {
return
}
idx := c.listWidget.SelectedRow
c.contentStartIdx -= maxContentLineSize
c.contentEndIdx -= maxContentLineSize
if c.contentEndIdx < 0 {
c.contentEndIdx = 0
oldStart := c.contentStartIdx
oldEnd := c.contentEndIdx

if c.contentEndIdx > 0 && c.contentEndIdx - maxContentLineSize > 0 && c.contentStartIdx > 0 && c.contentStartIdx - maxContentLineSize > 0 {
c.contentEndIdx -= maxContentLineSize
c.contentStartIdx -= maxContentLineSize
}
if c.contentStartIdx < 0 {
c.contentStartIdx = 0

if c.contentStartIdx >= c.contentEndIdx {
c.contentStartIdx = oldStart
c.contentEndIdx = oldEnd
}
c.contentWidget.Text = c.decorateText(idx, c.contentStartIdx, c.contentEndIdx)
}
Expand All @@ -265,7 +277,7 @@ func (c *Content)contentInitPage() {
idx := c.listWidget.SelectedRow
lines := strings.Split(c.listEntries[idx].detail.String(), "\n")
c.contentStartIdx = 0
c.contentEndIdx = maxContentLineSize * 2
c.contentEndIdx = displayLineSize
if c.contentEndIdx > len(lines) {
c.contentEndIdx = len(lines)
}
Expand Down Expand Up @@ -297,28 +309,34 @@ func (c *Content) HandleEvent(e ui.Event) (ui.Drawable, bool, bool) {
c.loadContent()
return c.listWidget, false, false
case "<Enter>":
if c.widgetType == ListType {
c.contentInitPage()
c.widgetType = ContentType
// 记录
*c.recHistoryCommandChan <- c.listEntries[c.listWidget.SelectedRow].command.String()
if len(c.listWidget.Rows) > 0 {
if c.widgetType == ListType {
c.contentInitPage()
c.widgetType = ContentType
// 记录
*c.recHistoryCommandChan <- c.listEntries[c.listWidget.SelectedRow].command.String()
}
}
return c.contentWidget, false, false
case "<Down>":
if c.widgetType == ListType {
c.listWidget.ScrollDown()
return c.listWidget, false, false
} else {
c.contentDownPage()
return c.contentWidget, false, false
if len(c.listWidget.Rows) > 0 {
if c.widgetType == ListType {
c.listWidget.ScrollDown()
return c.listWidget, false, false
} else {
c.contentDownPage()
return c.contentWidget, false, false
}
}
case "<Up>":
if c.widgetType == ListType {
c.listWidget.ScrollUp()
return c.listWidget, false, false
} else {
c.contentUpPage()
return c.contentWidget, false, false
if len(c.listWidget.Rows) > 0 {
if c.widgetType == ListType {
c.listWidget.ScrollUp()
return c.listWidget, false, false
} else {
c.contentUpPage()
return c.contentWidget, false, false
}
}
case "<Left>":
c.setColor()
Expand Down
Binary file added fastfind
Binary file not shown.
4 changes: 2 additions & 2 deletions history.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ func (i *History) HandleEvent(e ui.Event) (ui.Drawable, bool, bool) {
i.setColor()
return i.widget, true, true
case "<Right>":
cursor = 0
cursor = 1
i.setColor()
return i.widget, false, false
return i.widget, true, false
default:
return i.widget, true, false
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func main() {
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
if e.Type != ui.KeyboardEvent {
continue
}
//if e.Type != ui.KeyboardEvent {
// continue
//}
var next bool
var repeat = true

Expand Down

0 comments on commit f665a83

Please sign in to comment.