Upgrade to Pro — share decks privately, control downloads, hide ads and more …

システムライブラリに依存しないlessコマンドAPIの簡易版を作った

wasanx25
May 18, 2019
1.2k

 システムライブラリに依存しないlessコマンドAPIの簡易版を作った

wasanx25

May 18, 2019
Tweet

Transcript

  1. GOSS ▸ https://github.com/wasanx25/goss ▸ Go͔Βͦͷ··ςΩετΛ౉͚ͩ͢Ͱɺλʔϛφϧ্Ͱless Έ͍ͨʹදࣔ͢Δ func main() { data

    := "text, text\ntext,text" err := goss.Run(data) if err != nil { fmt.Println(err) os.Exit(1) } os.Exit(0) }
  2. TCELLͱ͍͏OSSΛ࢖͍ͬͯΔ ▸ https://github.com/gdamore/tcell func main() { tui, err := tcell.NewScreen()

    if err != nil { fmt.Println(err) os.Exit(1) } if err = tui.Init(); err != nil { fmt.Println(err) os.Exit(1) } tui.SetContent(0, 0, 't', nil, tcell.StyleDefault) tui.SetContent(1, 0, 'e', nil, tcell.StyleDefault) tui.SetContent(2, 0, 's', nil, tcell.StyleDefault) tui.SetContent(3, 0, 't', nil, tcell.StyleDefault) tui.SetContent(0, 1, 's', []rune{'a','m','p','l','e'}, tcell.StyleDefault) tui.Show() time.Sleep(5 * time.Second) tui.Fini() } ▸ tui͸ɺtcell.Screen IntefaceΛ࣋ͭ
  3. TCELLͷςετ ▸ ઌ΄Ͳͷ࣮ߦαϯϓϧΛ sample() ͱ͍͏ϝιουʹஔ͘ func sample(tui tcell.Screen) { tui.SetContent(0,

    0, 't', nil, tcell.StyleDefault) tui.SetContent(1, 0, 'e', nil, tcell.StyleDefault) tui.SetContent(2, 0, 's', nil, tcell.StyleDefault) tui.SetContent(3, 0, 't', nil, tcell.StyleDefault) tui.SetContent(0, 1, 's', []rune{'a', 'm', 'p', 'l', 'e'}, tcell.StyleDefault) }
  4. TCELLͷςετ func TestSample(t *testing.T) { tui := tcell.NewSimulationScreen("") if err

    := tui.Init(); err != nil { t.Fatal(err) } tui.SetSize(10, 2) sample(tui) tui.Show() cells, _, _ := tui.GetContents() var runes []rune for i, cell := range cells { runes = append(runes, cell.Runes...) if (i+1)%10 == 0 { runes = append(runes, '\n') } } slice := []string{ "test \n", "sample \n", } expected := strings.Join(slice, "") actual := string(runes) if actual != expected { t.Errorf("expected=%v, got=%v", expected, actual) } } ▸ GetContents()ͷୈҰҾ਺͸ɺ []tcell.SimCell type ▸ []runeͳͲΛϑΟʔϧυʹ࣋ͭ ▸ tui.SetSize()͞Εͨ৘ใʹج͍ͮͯ TERMͷWindowαΠζΛܾΊΔ ▸ ஫ʣจࣈͰຒ·Βͳ͔ͬͨͱ͜ Ζ͸εϖʔεͰຒ·Δ
  5. ύοέʔδͷߏ੒ ▸ Drawer ▸ contentʢҾ਺Ͱ౉͖ͬͯͨςΩετΛѻ͏ʣ ▸ numberʢߦ൪߸Λѻ͏ʣ ▸ positionerʢWrite͢Δ৔ॴΛ؅ཧʣ ▸

    ্هೋͭ͸ɺ͜ΕΛϑΟʔϧυͱͯͦ͠ΕͧΕ ࣋ͭ ▸ Event ▸ eventʢΩʔ΍TERMͷϦαΠζͷΠϕϯτΛ؅ཧʣ ▸ Offsetter ▸ offsetterʢॻ͖ࠐΉ಺༰ͷoffsetαΠζΛ؅ཧʣ ▸ Viewer ▸ viewerʢ্هΛ؅ཧͯ͠ɺ࣮ࡍʹදࣔͤ͞Δʣ
  6. ࣗݾ঺հ ▸ @wasanx25 ▸ ຊۀ: Java, Kotlin, Spring Boot ▸

    झຯ: Go, Ruby ▸ Go͸πʔϧ࡞Δ͙Β͍͔͠