Go 언어 컨트롤러 모드에서 컨트롤러에 도표, 단추, 스크롤 텍스트를 표시하는termdash를 소개합니다
개요
나는 보통 컨트롤러에서 텍스트만 표시할 수 있다고 생각했다.소개된termdash를 사용하면 컨트롤러에 GUI가 되돌아오는 것을 표시할 수 있습니다.
기능
다음 그림은 Windows에서 보여 줍니다.
다음은 화면 중앙의 흰색 버튼sparklines
을 마우스로 눌렀을 때의 화면입니다.
다음 URL에서는 시간에 따라 차트가 변경되는 애니메이션을 볼 수 있습니다.
다음 그림은 Windows에서 보여 줍니다.
다음은 화면 중앙의 흰색 버튼
sparklines
을 마우스로 눌렀을 때의 화면입니다.다음 URL에서는 시간에 따라 차트가 변경되는 애니메이션을 볼 수 있습니다.
각 운영 체제에서 실행
chcp 65001
UTF-8로 설정하지 않으면 화면이 혼란스러워진다Sparkline
횡근git bash
의 ssh)Scroll text로 두 개의 로그 콘솔 화면 구현
화면은 다음과 같습니다.왼쪽은 Fatal 로그, 오른쪽은 Information 로그입니다.아래 화면이 오른쪽을 눌렀기 때문에 테두리의 색깔은 노란색?따라서 마우스 가운데 단추나 키보드의 커서 단추로 위아래로 스크롤할 수 있다.로그의 텍스트가 축소되면 화면을 가로로 확장하여 크기를 조정합니다.숫자 시간은 빨간색이고 정보는 파란색이다.
소스 코드
나는 단지 간단하게 시범의 출처를 개조했을 뿐이다.Fatal인지 여부는 무작위로 결정됩니다.실제로는 로그 파일, 데이터베이스, 네트워크에서 얻은 것이다.container.SplitVertical
를 사용하여 화면을 세로로 두 부분으로 분할합니다.
main.gopackage main
import (
"context"
"fmt"
"math/rand"
"time"
"github.com/mum4k/termdash"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/container"
"github.com/mum4k/termdash/linestyle"
"github.com/mum4k/termdash/terminal/termbox"
"github.com/mum4k/termdash/terminal/terminalapi"
"github.com/mum4k/termdash/widgets/text"
)
func writeLines(ctx context.Context, fatal, info *text.Text, delay time.Duration) {
s := rand.NewSource(time.Now().Unix())
r := rand.New(s)
ticker := time.NewTicker(delay)
defer ticker.Stop()
fatalCount := 0
infoCount := 0
for {
select {
case <-ticker.C:
var err error
d := time.Now().Format("03:04:05")
i := r.Intn(3)
if i == 0 {
fatal.Write(d, text.WriteCellOpts(cell.FgColor(cell.ColorRed)))
if err == nil {
fatalCount++
log := fmt.Sprintf(" %d fatal fatal fatal\n", fatalCount)
err = fatal.Write(log)
}
} else {
err = info.Write(d, text.WriteCellOpts(cell.FgColor(cell.ColorCyan)))
if err == nil {
infoCount++
log := fmt.Sprintf(" %d information information information\n", infoCount)
err = info.Write(log)
}
}
if err != nil {
panic(err)
}
case <-ctx.Done():
return
}
}
}
func main() {
t, err := termbox.New()
if err != nil {
panic(err)
}
defer t.Close()
ctx, cancel := context.WithCancel(context.Background())
rolledFatal, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
panic(err)
}
rolledInfo, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
panic(err)
}
go writeLines(ctx, rolledFatal, rolledInfo, 1*time.Second)
c, err := container.New(
t,
container.Border(linestyle.Light),
container.BorderTitle("PRESS Q TO QUIT"),
container.SplitVertical(
container.Left(
container.Border(linestyle.Light),
container.BorderTitle(" Fatal ログ"),
container.PlaceWidget(rolledFatal),
),
container.Right(
container.Border(linestyle.Light),
container.BorderTitle(" Information ログ"),
container.PlaceWidget(rolledInfo),
),
),
)
if err != nil {
panic(err)
}
quitter := func(k *terminalapi.Keyboard) {
if k.Key == 'q' || k.Key == 'Q' {
cancel()
}
}
if err := termdash.Run(ctx, t, c, termdash.KeyboardSubscriber(quitter)); err != nil {
panic(err)
}
}
총결산
서버계 모니터 화면에서 사용할 수 있지 않을까요?콘솔에서 마우스를 사용할 수 있을 줄은 생각지도 못했다.
각 Layout, Widget의 사용법을 QIITA에 게재할 수 있다면 기쁩니다.
git bash의 ssh보다 더 적합한 Windows SSH 소프트웨어가 있다면 알려주세요.
Reference
이 문제에 관하여(Go 언어 컨트롤러 모드에서 컨트롤러에 도표, 단추, 스크롤 텍스트를 표시하는termdash를 소개합니다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/h6591/items/2964ec7c8d8e53d5ac0a
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
package main
import (
"context"
"fmt"
"math/rand"
"time"
"github.com/mum4k/termdash"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/container"
"github.com/mum4k/termdash/linestyle"
"github.com/mum4k/termdash/terminal/termbox"
"github.com/mum4k/termdash/terminal/terminalapi"
"github.com/mum4k/termdash/widgets/text"
)
func writeLines(ctx context.Context, fatal, info *text.Text, delay time.Duration) {
s := rand.NewSource(time.Now().Unix())
r := rand.New(s)
ticker := time.NewTicker(delay)
defer ticker.Stop()
fatalCount := 0
infoCount := 0
for {
select {
case <-ticker.C:
var err error
d := time.Now().Format("03:04:05")
i := r.Intn(3)
if i == 0 {
fatal.Write(d, text.WriteCellOpts(cell.FgColor(cell.ColorRed)))
if err == nil {
fatalCount++
log := fmt.Sprintf(" %d fatal fatal fatal\n", fatalCount)
err = fatal.Write(log)
}
} else {
err = info.Write(d, text.WriteCellOpts(cell.FgColor(cell.ColorCyan)))
if err == nil {
infoCount++
log := fmt.Sprintf(" %d information information information\n", infoCount)
err = info.Write(log)
}
}
if err != nil {
panic(err)
}
case <-ctx.Done():
return
}
}
}
func main() {
t, err := termbox.New()
if err != nil {
panic(err)
}
defer t.Close()
ctx, cancel := context.WithCancel(context.Background())
rolledFatal, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
panic(err)
}
rolledInfo, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
panic(err)
}
go writeLines(ctx, rolledFatal, rolledInfo, 1*time.Second)
c, err := container.New(
t,
container.Border(linestyle.Light),
container.BorderTitle("PRESS Q TO QUIT"),
container.SplitVertical(
container.Left(
container.Border(linestyle.Light),
container.BorderTitle(" Fatal ログ"),
container.PlaceWidget(rolledFatal),
),
container.Right(
container.Border(linestyle.Light),
container.BorderTitle(" Information ログ"),
container.PlaceWidget(rolledInfo),
),
),
)
if err != nil {
panic(err)
}
quitter := func(k *terminalapi.Keyboard) {
if k.Key == 'q' || k.Key == 'Q' {
cancel()
}
}
if err := termdash.Run(ctx, t, c, termdash.KeyboardSubscriber(quitter)); err != nil {
panic(err)
}
}
서버계 모니터 화면에서 사용할 수 있지 않을까요?콘솔에서 마우스를 사용할 수 있을 줄은 생각지도 못했다.
각 Layout, Widget의 사용법을 QIITA에 게재할 수 있다면 기쁩니다.
git bash의 ssh보다 더 적합한 Windows SSH 소프트웨어가 있다면 알려주세요.
Reference
이 문제에 관하여(Go 언어 컨트롤러 모드에서 컨트롤러에 도표, 단추, 스크롤 텍스트를 표시하는termdash를 소개합니다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/h6591/items/2964ec7c8d8e53d5ac0a텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)