()
| 106 | } |
| 107 | |
| 108 | func (m *TuiModel) SetViewSlices() { |
| 109 | d := m.Data() |
| 110 | if m.Viewport.Height < 0 { |
| 111 | return |
| 112 | } |
| 113 | if m.UI.FormatModeEnabled { |
| 114 | var slices []*string |
| 115 | for i := 0; i < m.Viewport.Height; i++ { |
| 116 | yOffset := Max(m.Viewport.YOffset, 0) |
| 117 | if yOffset+i > len(m.Format.Text)-1 { |
| 118 | break |
| 119 | } |
| 120 | pStr := &m.Format.Text[Max(yOffset+i, 0)] |
| 121 | slices = append(slices, pStr) |
| 122 | } |
| 123 | m.Format.EditSlices = slices |
| 124 | m.UI.CanFormatScroll = len(m.Format.Text)-m.Viewport.YOffset-m.Viewport.Height > 0 |
| 125 | if m.Format.CursorX < 0 { |
| 126 | m.Format.CursorX = 0 |
| 127 | } |
| 128 | } else { |
| 129 | // header slices |
| 130 | headers := d.TableHeaders[m.GetSchemaName()] |
| 131 | headersLen := len(headers) |
| 132 | |
| 133 | if headersLen > maxHeaders { |
| 134 | headers = headers[m.Scroll.ScrollXOffset : maxHeaders+m.Scroll.ScrollXOffset-1] |
| 135 | } |
| 136 | // data slices |
| 137 | defer func() { |
| 138 | if recover() != nil { |
| 139 | panic(errors.New("adsf")) |
| 140 | } |
| 141 | }() |
| 142 | |
| 143 | for _, columnName := range headers { |
| 144 | interfaceValues := m.GetSchemaData()[columnName] |
| 145 | if len(interfaceValues) >= m.Viewport.Height { |
| 146 | min := Min(m.Viewport.YOffset, len(interfaceValues)-m.Viewport.Height) |
| 147 | |
| 148 | d.TableSlices[columnName] = interfaceValues[min : m.Viewport.Height+min] |
| 149 | } else { |
| 150 | d.TableSlices[columnName] = interfaceValues |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | d.TableHeadersSlice = headers |
| 155 | } |
| 156 | // format slices |
| 157 | } |
| 158 | |
| 159 | // GetSchemaData is a helper function to get the data of the current schema |
| 160 | func (m *TuiModel) GetSchemaData() map[string][]interface{} { |
no test coverage detected