func (p *TicketListPage) Create() { log.Debugf("TicketListPage.Create(): self: %s (%p)", p.Id(), p) log.Debugf("TicketListPage.Create(): currentPage: %s (%p)", currentPage.Id(), currentPage) ui.Clear() ls := ui.NewList() p.uiList = ls if p.statusBar == nil { p.statusBar = new(StatusBar) } if p.commandBar == nil { p.commandBar = commandBar } query := p.ActiveQuery.JQL if sort := p.ActiveSort.JQL; sort != "" { re := regexp.MustCompile(`(?i)\s+ORDER\s+BY.+$`) query = re.ReplaceAllString(query, ``) + " " + sort } if len(p.cachedResults) == 0 { p.cachedResults = JiraQueryAsStrings(query, p.ActiveQuery.Template) } if p.selectedLine >= len(p.cachedResults) { p.selectedLine = len(p.cachedResults) - 1 } p.displayLines = make([]string, len(p.cachedResults)) ls.ItemFgColor = ui.ColorYellow ls.BorderLabel = fmt.Sprintf("%s: %s", p.ActiveQuery.Name, p.ActiveQuery.JQL) ls.Height = ui.TermHeight() - 2 ls.Width = ui.TermWidth() ls.Y = 0 p.statusBar.Create() p.commandBar.Create() p.Update() }
func (ui *tatui) showMessages() { ui.current = uiMessages ui.selectedPane = uiMessages ui.send.BorderLabel = " ✎ Action or New Message " termui.Body.Rows = nil ui.selectedPaneMessages = 0 if len(ui.currentListMessages) == 0 { ui.currentListMessages[0] = nil } if _, ok := ui.uilists[uiTopics]; !ok || len(ui.uilists[uiTopics]) == 0 { ui.msg.Text = "Please select a topic before doing this action" ui.showHome() return } if _, ok := ui.currentFilterMessages[ui.currentTopic.Topic]; !ok { ui.clearFilterOnCurrentTopic() } ui.initMessages() go func() { for { if ui.current != uiMessages { break } mutex.Lock() ui.updateMessages() ui.firstCallMessages = true mutex.Unlock() time.Sleep(5 * time.Second) } }() ui.uilists[uiTopics][0].list.BorderRight = true ui.prepareTopMenu() if len(ui.currentFilterMessages[ui.currentTopic.Topic]) > 1 { // preserve order for k := 0; k < len(ui.currentFilterMessages[ui.currentTopic.Topic]); k++ { termui.Body.AddRows(termui.NewRow(termui.NewCol(12, 0, ui.uilists[uiMessages][k].list))) } } else { termui.Body.AddRows( termui.NewRow( termui.NewCol(3, 0, ui.uilists[uiTopics][0].list), termui.NewCol(9, 0, ui.uilists[uiMessages][0].list), ), ) } ui.prepareSendRow() ui.colorizedPanes() termui.Clear() ui.render() }
func (p *LabelListPage) Create() { ui.Clear() ls := ui.NewList() p.uiList = ls if p.statusBar == nil { p.statusBar = new(StatusBar) } if p.commandBar == nil { p.commandBar = commandBar } queryName := p.ActiveQuery.Name queryJQL := p.ActiveQuery.JQL p.labelCounts = countLabelsFromQuery(queryJQL) p.cachedResults = p.labelsAsSortedList() p.isPopulated = true p.displayLines = make([]string, len(p.cachedResults)) ls.ItemFgColor = ui.ColorYellow ls.BorderLabel = fmt.Sprintf("Label view -- %s: %s", queryName, queryJQL) ls.Height = ui.TermHeight() - 2 ls.Width = ui.TermWidth() ls.Y = 0 p.statusBar.Create() p.commandBar.Create() p.Update() }
func (p *TicketShowPage) Create() { log.Debugf("TicketShowPage.Create(): self: %s (%p)", p.Id(), p) log.Debugf("TicketShowPage.Create(): currentPage: %s (%p)", currentPage.Id(), currentPage) p.opts = getJiraOpts() if p.TicketId == "" { p.TicketId = ticketListPage.GetSelectedTicketId() } if p.MaxWrapWidth == 0 { if m := p.opts["max_wrap"]; m != nil { p.MaxWrapWidth = uint(m.(int64)) } else { p.MaxWrapWidth = defaultMaxWrapWidth } } ui.Clear() ls := ui.NewList() if p.statusBar == nil { p.statusBar = new(StatusBar) } if p.commandBar == nil { p.commandBar = commandBar } p.uiList = ls if p.Template == "" { if templateOpt := p.opts["template"]; templateOpt == nil { p.Template = "jira_ui_view" } else { p.Template = templateOpt.(string) } } innerWidth := uint(ui.TermWidth()) - 3 if innerWidth < p.MaxWrapWidth { p.WrapWidth = innerWidth } else { p.WrapWidth = p.MaxWrapWidth } if p.apiBody == nil { p.apiBody, _ = FetchJiraTicket(p.TicketId) } p.cachedResults = WrapText(JiraTicketAsStrings(p.apiBody, p.Template), p.WrapWidth) p.displayLines = make([]string, len(p.cachedResults)) if p.selectedLine >= len(p.cachedResults) { p.selectedLine = len(p.cachedResults) - 1 } ls.ItemFgColor = ui.ColorYellow ls.Height = ui.TermHeight() - 2 ls.Width = ui.TermWidth() ls.Border = true ls.BorderLabel = fmt.Sprintf("%s %s", p.TicketId, p.ticketTrailAsString()) ls.Y = 0 p.statusBar.Create() p.commandBar.Create() p.Update() }
func (p *BaseListPage) Create() { ui.Clear() ls := ui.NewList() p.uiList = ls p.cachedResults = make([]string, 0) p.displayLines = make([]string, len(p.cachedResults)) ls.ItemFgColor = ui.ColorYellow ls.BorderLabel = "Updating, please wait" ls.Height = ui.TermHeight() ls.Width = ui.TermWidth() ls.Y = 0 p.Update() }
func (ui *tatui) switchBox() { switch ui.current { case uiHome, uiResult: ui.switchBoxFromHome() case uiTopics: ui.switchBoxFromTopics() case uiMessages: ui.switchBoxFromMessages() case uiMessage: ui.switchBoxFromMessage() } ui.colorizedPanes() termui.Clear() ui.render() }
func (ui *tatui) showHome() { ui.current = uiHome ui.selectedPane = uiActionBox termui.Body.Rows = nil ui.prepareTopMenu() termui.Body.AddRows( termui.NewRow( termui.NewCol(5, 0, ui.homeLeft), termui.NewCol(7, 0, ui.homeRight), ), ) ui.prepareSendRow() termui.Clear() ui.colorizedPanes() ui.render() }
func (ui *tatui) showMessage() { ui.current = uiMessage ui.selectedPane = uiMessage ui.send.BorderLabel = " ✎ Action or New Reply " termui.Body.Rows = nil if ui.uilists[uiMessages][ui.selectedPaneMessages].list == nil || ui.uilists[uiMessages][ui.selectedPaneMessages].position < 0 { return } ui.uilists[uiMessage] = make(map[int]*uilist) ui.initMessage() go func() { for { if ui.current != uiMessage { break } mutex.Lock() ui.updateMessage() mutex.Unlock() time.Sleep(5 * time.Second) } }() ui.addMarker(ui.uilists[uiMessage][0], 0) ui.prepareTopMenu() termui.Body.AddRows( termui.NewRow( termui.NewCol(3, 0, ui.uilists[uiTopics][0].list), termui.NewCol(9, 0, ui.uilists[uiMessage][0].list), ), ) ui.prepareSendRow() ui.colorizedPanes() termui.Clear() ui.render() }
func (ui *tatui) showResult(cmdResult, result string) { ui.current = uiResult ui.send.BorderLabel = " ✎ Action" termui.Body.Rows = nil p := termui.NewPar(`Result of ` + cmdResult + `: ` + result + ` `) p.Height = termui.TermHeight() - uiHeightTop - uiHeightSend p.TextFgColor = termui.ColorWhite p.BorderTop = true ui.prepareTopMenu() termui.Body.AddRows( termui.NewRow( termui.NewCol(12, 0, p), ), ) ui.prepareSendRow() termui.Clear() }
func (p *QueryPage) Create() { log.Debugf("QueryPage.Create(): self: %s (%p)", p.Id(), p) log.Debugf("QueryPage.Create(): currentPage: %s (%p)", currentPage.Id(), currentPage) ui.Clear() ls := ui.NewList() p.uiList = ls if p.statusBar == nil { p.statusBar = new(StatusBar) } if p.commandBar == nil { p.commandBar = commandBar } p.cachedResults = getQueries() p.displayLines = make([]string, len(p.cachedResults)) ls.ItemFgColor = ui.ColorYellow ls.BorderLabel = "Queries" ls.Height = ui.TermHeight() - 2 ls.Width = ui.TermWidth() ls.Y = 0 p.statusBar.Create() p.commandBar.Create() p.Update() }
func (p *HelpPage) Create() { ui.Clear() ls := ui.NewList() p.uiList = ls if p.statusBar == nil { p.statusBar = new(StatusBar) } if p.commandBar == nil { p.commandBar = commandBar } if len(p.cachedResults) == 0 { p.cachedResults = HelpTextAsStrings(nil, "jira_ui_help") } p.displayLines = make([]string, len(p.cachedResults)) ls.ItemFgColor = ui.ColorYellow ls.BorderLabel = "Help" ls.Height = ui.TermHeight() - 2 ls.Width = ui.TermWidth() ls.Y = 0 p.statusBar.Create() p.commandBar.Create() p.Update() }
func (ui *tatui) showTopics() { ui.current = uiTopics ui.selectedPane = uiTopics ui.send.BorderLabel = " ✎ Action " ui.msg.Text = "tab or enter to select topic" termui.Body.Rows = nil ui.initTopics() ui.updateTopics() go func() { for { if ui.current != uiTopics { break } time.Sleep(10 * time.Second) mutex.Lock() ui.updateTopics() mutex.Unlock() } }() ui.uilists[uiTopics][0].list.BorderRight = false ui.prepareTopMenu() termui.Body.AddRows( termui.NewRow( termui.NewCol(12, 0, ui.uilists[uiTopics][0].list), ), ) ui.prepareSendRow() termui.Clear() ui.colorizedPanes() ui.render() }
func (sc *sparkyClient) protocolError(err error) { termui.Clear() termui.Close() log.Fatalln(err) }
func (v *View) Render() { ui.Clear() ui.Render(ui.Body) }
func fatalError(err error) { termui.Clear() termui.Close() log.Fatal(err) }
func (d *Dash) Start() { go d.run() go mock() PL := MAX_WIDTH / d.width err := termui.Init() if err != nil { panic(err) } defer termui.Close() var lists []termui.Bufferer draw := func() { newRow := false row := 0 if d.dashboard { row = 1 // row=0 :view } d.lock.Lock() var hosts []string if len(d.hosts) == 0 { hosts = d.sortHost() } else { hosts = d.hosts } index := 0 for _, h := range hosts { for s := range d.stat[h] { st, ok := d.stat[h][s] if !ok { continue } ls := termui.NewList() ls.Items = st.List() ls.ItemFgColor = termui.ColorYellow ls.BorderLabel = fmt.Sprintf("%s@%s", s, h) ls.Height = d.height ls.Width = d.width ls.X = (index % PL) * d.width if index >= PL && index%PL == 0 { newRow = true } if newRow { row++ } ls.Y = d.height * row newRow = false d.gList = append(d.gList, ls) index++ if index%d.page == 0 && index != 1 { index = 0 row = 0 newRow = false } } } d.lock.Unlock() if len(d.gList) > d.page { lists = d.gList[:d.page] } else { lists = d.gList[:] } } termui.Render(lists...) termui.Handle("/timer/1s", func(e termui.Event) { if len(lists) == 0 { draw() } if d.dashboard { d.drawView() termui.Render(d.view) } else { for index := range lists { ls := lists[index].(*termui.List) dd := strings.Split(ls.BorderLabel, "@") sv, pc := dd[0], dd[1] d.lock.RLock() ls.Items = d.stat[pc][sv].List() d.lock.RUnlock() lists[index] = ls } termui.Render(lists...) } }) termui.Handle("/sys/kbd/q", func(termui.Event) { termui.StopLoop() }) termui.Handle("/sys/kbd/p", func(termui.Event) { termui.Clear() start := (d.curPage - 1) * d.page if start < 0 { start = 0 } else { d.curPage-- } lists = d.gList[start : start+d.page] d.lock.Lock() for index := range lists { ls := lists[index].(*termui.List) dd := strings.Split(ls.BorderLabel, "@") sv, pc := dd[0], dd[1] ls.Items = d.stat[sv][pc].List() lists[index] = ls } d.lock.Unlock() termui.Render(lists...) }) termui.Handle("/sys/kbd/n", func(termui.Event) { termui.Clear() end := (d.curPage + 1) * d.page if end > len(d.gList) { end = len(d.gList) - 1 } else { d.curPage++ } lists = d.gList[end-d.page : end] d.lock.Lock() for index := range lists { ls := lists[index].(*termui.List) dd := strings.Split(ls.BorderLabel, "@") sv, pc := dd[0], dd[1] ls.Items = d.stat[sv][pc].List() lists[index] = ls } d.lock.Unlock() termui.Render(lists...) }) termui.Handle("/sys/kbd/a", func(termui.Event) { termui.Clear() d.dashboard = true }) termui.Handle("/sys/kbd/s", func(termui.Event) { termui.Clear() d.dashboard = false }) termui.Loop() }