Go 언어 컨트롤러 모드에서 컨트롤러에 도표, 단추, 스크롤 텍스트를 표시하는termdash를 소개합니다

17810 단어 termdashGo

개요


나는 보통 컨트롤러에서 텍스트만 표시할 수 있다고 생각했다.소개된termdash를 사용하면 컨트롤러에 GUI가 되돌아오는 것을 표시할 수 있습니다.

기능


다음 그림은 Windows에서 보여 줍니다.

다음은 화면 중앙의 흰색 버튼sparklines을 마우스로 눌렀을 때의 화면입니다.

다음 URL에서는 시간에 따라 차트가 변경되는 애니메이션을 볼 수 있습니다.
  • Github URL
  • https://github.com/mum4k/termdash
  • 레이아웃
  • Binary tree layout
  • https://github.com/mum4k/termdash/wiki/Binary-tree-layout
  • 세로 또는 가로로 두 부분으로 분할한다.그것들을 각각 두 부분으로 분할하는 방법으로 화면을 구성한다.
  • 저는 이걸 주로 해봤어요
  • .
  • 화면 크기 조정도 지원됩니다.
  • Grid layout
  • https://github.com/mum4k/termdash/wiki/Grid-layout
  • 나는 이것이 일반적인 Grid라고 생각한다.아직 안 해봤어요.
  • Widget
  • BarChart 막대 그림(이미지의 오른쪽 위)
  • https://github.com/mum4k/termdash/wiki/Barchart-API
  • 버튼(이미지의 중앙 4 버튼 및 오른쪽 아래 2 버튼)
  • Donut 원형도(이미지의 BarChart 아래)
  • Gauge 게이지(이미지 중앙의 녹색 띠)
  • LineChart 차트(이미지 아래, 마우스 크기 조정 기능)
  • SegmentDisplay 조사되지 않음
  • Sparkline 미니어처(이미지 센터)
  • Text(이미지의 중앙)
  • 스크롤
  • 마우스 또는 키보드를 통해 스크롤할 수 있습니다.
  • 텍스트 줄 바꿈
  • 오버플로우 부분 생략
  • 각 운영 체제에서 실행

  • Windows 위의 이미지와 같이 문제 없음
  • 일본어와 중국어 등을 표시할 때chcp 65001 UTF-8로 설정하지 않으면 화면이 혼란스러워진다
  • Mac에 문제가 거의 없음Sparkline 횡근
  • Linux  (ubuntu 18.04)
  • Linux 화면을 직접 조작하지 않기 때문에 아래의 ssh로 시도해 보았습니다.
  • Mac ssh에서 Mac과 동일
  • Windows(권장 git bash의 ssh)
  • git bash의 ssh
  • 가장 좋음
  • 버튼
  • 을 눌러도 됩니다.
  • sparkline 디스플레이에 칠하지 않은 사각 문자가 나타나면(괜찮다면 문제없음)
  • 스크롤 텍스트에 스크롤된 특수 문자가 표시되지 않음
  • putty
  • 도표가 나왔지만 상자의 격선이 혼란스러웠다
  • 버튼을 누를 수 없음
  • openssh
  • 시간 변화의 곡선도 등 혼란.
  • 버튼을 누를 수 없음
  • 일부 상자의 격자 혼란
  • WSL(ubuntu18.04)의 ssh
  • LineChart 혼란
  • Donut 혼란
  • 중앙에 흰색 버튼이 안 나와요
  • 오른쪽 아래 단추가 표시되고 클릭할 수도 있습니다.
  • Scroll text로 두 개의 로그 콘솔 화면 구현


    화면은 다음과 같습니다.왼쪽은 Fatal 로그, 오른쪽은 Information 로그입니다.아래 화면이 오른쪽을 눌렀기 때문에 테두리의 색깔은 노란색?따라서 마우스 가운데 단추나 키보드의 커서 단추로 위아래로 스크롤할 수 있다.로그의 텍스트가 축소되면 화면을 가로로 확장하여 크기를 조정합니다.숫자 시간은 빨간색이고 정보는 파란색이다.

    소스 코드


    나는 단지 간단하게 시범의 출처를 개조했을 뿐이다.Fatal인지 여부는 무작위로 결정됩니다.실제로는 로그 파일, 데이터베이스, 네트워크에서 얻은 것이다.container.SplitVertical를 사용하여 화면을 세로로 두 부분으로 분할합니다.
    main.go
    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 소프트웨어가 있다면 알려주세요.

    좋은 웹페이지 즐겨찾기