Prechádzať zdrojové kódy

Fixed a display bug in the tui

arianagiroux 1 týždeň pred
rodič
commit
bf7dbd001f
2 zmenil súbory, kde vykonal 9 pridanie a 9 odobranie
  1. 6 6
      tui.go
  2. 3 3
      tui_test.go

+ 6 - 6
tui.go

@@ -87,7 +87,7 @@ func InitialModel(addresses []string, speed time.Duration, chartHeight int) Mode
 
 	for _, address := range addresses {
 		var addr Address
-		addr.max_results = 80
+		addr.MaxResults = 80
 		addr.Address = address
 		model.Addresses = append(model.Addresses, addr)
 	}
@@ -121,7 +121,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		m.ModelWidth = msg.Width
 		m.ModelHeight = msg.Height
 		for i, address := range m.Addresses {
-			address.max_results = m.ModelWidth
+			address.MaxResults = m.ModelWidth
 			m.Addresses[i] = address
 		}
 		m.viewport.SetHeight(m.ModelHeight - m.getVerticalMargin())
@@ -143,7 +143,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		cmds = append(cmds, m.Tick(), m.Poll())
 
 	case pollResultMsg:
-		m.Addresses[msg.index].results = msg.results
+		m.Addresses[msg.index].Results = msg.results
 	}
 
 	m.viewport.SetContent(m.Render())
@@ -165,10 +165,10 @@ func (m Model) View() tea.View {
 func (m Model) Render() string {
 	var output string
 	for _, address := range m.Addresses {
-		if len(address.results) == 0 {
+		if len(address.Results) == 0 {
 			output = output + fmt.Sprintf("\n%s\tloading...", headerStyle.Render(address.Address))
 		} else if m.ModelWidth != 0 && m.ModelHeight != 0 {
-			if slices.Contains(address.results, -1) {
+			if slices.Contains(address.Results, -1) {
 				output = output + blockStyle.Width(m.ModelWidth).Render(headerStyle.Render(
 					fmt.Sprintf("\n%s\t%s",
 						secondaryColor.Render(address.Address),
@@ -196,7 +196,7 @@ func (m Model) Render() string {
 				slc = streamlinechart.New(m.ModelWidth, m.ChartHeight)
 			}
 
-			for _, v := range address.results {
+			for _, v := range address.Results {
 				slc.Push(v)
 			}
 

+ 3 - 3
tui_test.go

@@ -23,7 +23,7 @@ func Test_InitialModel(t *testing.T) {
 	assert.Equal(t, chartHeight, model.ChartHeight)
 	assert.Equal(t, 2, len(model.Addresses))
 	for i, address := range model.Addresses {
-		assert.Equal(t, 80, address.max_results)
+		assert.Equal(t, 80, address.MaxResults)
 		assert.Equal(t, addresses[i], address.Address)
 	}
 }
@@ -87,7 +87,7 @@ func spawnTestModel(addresses []string, points []float64, width, height, cHeight
 	speed := time.Second * 1
 	testModel := InitialModel(addresses, speed, cHeight)
 	for i := range testModel.Addresses {
-		testModel.Addresses[i].results = points
+		testModel.Addresses[i].Results = points
 	}
 	testModel.ModelWidth = width
 	testModel.ModelHeight = height
@@ -108,7 +108,7 @@ func Test_Model_Update_handle_pollMsg(t *testing.T) {
 
 	model, batch := testModel.Update(msg)
 	assert.IsType(t, *new(tea.Cmd), batch)
-	assert.Equal(t, msg.results, model.(Model).Addresses[0].results)
+	assert.Equal(t, msg.results, model.(Model).Addresses[0].Results)
 }
 
 func Test_Model_View(t *testing.T) {