Created
December 14, 2017 12:17
-
-
Save syossan27/90c70d620cb4d9139bf40473eae7e282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (t *Termbox) Draw() { | |
| termbox.Clear(color["default"], color["default"]) | |
| commandHistory := t.Commands | |
| // 検索フォームの表示 | |
| displaySearchForm := "QUERY>" | |
| t.Print(0, 0, style["fg"], style["bg"], displaySearchForm) | |
| t.PrintSearchQuery(len(displaySearchForm), 0, style["fg"], style["bg"]) | |
| // 検索条件がある場合、検索条件に合致するコマンド履歴一覧を生成する | |
| // コマンド履歴配列が変更されるため、内部バッファのサイズも更新 | |
| if len(t.Filter.SearchQuery) != 0 { | |
| commandHistory = t.Filter.FilterResult(t.Commands) | |
| t.Buffer.Size = len(commandHistory) | |
| } | |
| // commandHistoryを順番に表示 | |
| for i := t.Buffer.Offset; i < len(commandHistory); i++ { | |
| command := commandHistory[i] | |
| // 選択済みかどうか | |
| number, exist := t.Selection.GetSelectedNumber(command.Index) | |
| // 表示させる文字列 | |
| var appendExecOrder string | |
| var displayCommand string | |
| var displayColorSet map[string]termbox.Attribute | |
| var displaySearchColorSet map[string]termbox.Attribute | |
| if exist { | |
| // 選択済の場合 | |
| appendExecOrder = strconv.Itoa(number) + ": " | |
| displayCommand = appendExecOrder + command.Content | |
| displayColorSet = map[string]termbox.Attribute { | |
| "fg": style["selectedFg"], | |
| "bg": style["selectedBg"], | |
| } | |
| displaySearchColorSet = map[string]termbox.Attribute { | |
| "fg": style["selectedSearchFg"], | |
| "bg": style["selectedSearchBg"], | |
| } | |
| } else { | |
| // 未選択の場合 | |
| displayCommand = command.Content | |
| displayColorSet = map[string]termbox.Attribute { | |
| "fg": style["fg"], | |
| "bg": style["bg"], | |
| } | |
| displaySearchColorSet = map[string]termbox.Attribute { | |
| "fg": style["searchFg"], | |
| "bg": style["searchBg"], | |
| } | |
| } | |
| // コマンド履歴の表示 | |
| if t.Buffer.CommandPosition == t.Selection.Index - t.Buffer.Offset { | |
| // カーソルの表示 | |
| t.PrintFullWidth(0, t.Buffer.CommandPosition, style["selectionFg"], style["selectionBg"], displayCommand) | |
| // 検索条件に合致した箇所に着色 | |
| // カーソル表示時は着色する色は固定 | |
| t.Print(len(appendExecOrder) + command.FilterIndex, t.Buffer.CommandPosition, color["cyan"], style["selectionBg"], string(t.Filter.SearchQuery)) | |
| // カーソルにあるコマンドを仮保存 | |
| t.Selection.Command = command | |
| } else { | |
| // 選択済か、未選択のコマンド履歴の表示 | |
| t.PrintFullWidth(0, t.Buffer.CommandPosition, displayColorSet["fg"], displayColorSet["bg"], displayCommand) | |
| // 検索条件に合致した箇所に着色 | |
| t.Print(len(appendExecOrder) + command.FilterIndex, t.Buffer.CommandPosition, displaySearchColorSet["fg"], displaySearchColorSet["bg"], string(t.Filter.SearchQuery)) | |
| } | |
| t.Buffer.CommandPosition++ | |
| } | |
| termbox.Flush() | |
| t.Buffer.ClearCommandPosition() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment