@@ -35,10 +35,24 @@ type Model struct {
3535 pokeTable table.Model
3636}
3737
38- func makeRow (name , element , colorStr string , numConversations int , positiveSentiment , negativeSentiment float32 ) table.Row {
38+ func makeRow (name , element string , numConversations int , positiveSentiment , negativeSentiment float32 ) table.Row {
39+ elementStyleFunc := func (input table.StyledCellFuncInput ) lipgloss.Style {
40+ switch input .Data .(string ) {
41+ case "Fire" :
42+ return lipgloss .NewStyle ().Foreground (lipgloss .Color (colorFire ))
43+ case "Water" :
44+ return lipgloss .NewStyle ().Foreground (lipgloss .Color (colorWater ))
45+ case "Plant" :
46+ return lipgloss .NewStyle ().Foreground (lipgloss .Color (colorPlant ))
47+ case "Electric" :
48+ return lipgloss .NewStyle ().Foreground (lipgloss .Color (colorElectric ))
49+ default :
50+ return lipgloss .NewStyle ().Foreground (lipgloss .Color (colorNormal ))
51+ }
52+ }
3953 return table .NewRow (table.RowData {
4054 columnKeyName : name ,
41- columnKeyElement : table .NewStyledCell (element , lipgloss . NewStyle (). Foreground ( lipgloss . Color ( colorStr )) ),
55+ columnKeyElement : table .NewStyledCellWithStyleFunc (element , elementStyleFunc ),
4256 columnKeyConversations : numConversations ,
4357 columnKeyPositiveSentiment : positiveSentiment ,
4458 columnKeyNegativeSentiment : negativeSentiment ,
@@ -58,13 +72,13 @@ func NewModel() Model {
5872 WithStyle (lipgloss .NewStyle ().Foreground (lipgloss .Color ("#c88" ))).
5973 WithFormatString ("%.1f%%" ),
6074 }).WithRows ([]table.Row {
61- makeRow ("Pikachu" , "Electric" , colorElectric , 2300648 , 21.9 , 8.54 ),
62- makeRow ("Eevee" , "Normal" , colorNormal , 636373 , 26.4 , 7.37 ),
63- makeRow ("Bulbasaur" , "Plant" , colorPlant , 352190 , 25.7 , 9.02 ),
64- makeRow ("Squirtle" , "Water" , colorWater , 241259 , 25.6 , 5.96 ),
65- makeRow ("Blastoise" , "Water" , colorWater , 162794 , 19.5 , 6.04 ),
66- makeRow ("Charmander" , "Fire" , colorFire , 265760 , 31.2 , 5.25 ),
67- makeRow ("Charizard" , "Fire" , colorFire , 567763 , 25.6 , 7.56 ),
75+ makeRow ("Pikachu" , "Electric" , 2300648 , 21.9 , 8.54 ),
76+ makeRow ("Eevee" , "Normal" , 636373 , 26.4 , 7.37 ),
77+ makeRow ("Bulbasaur" , "Plant" , 352190 , 25.7 , 9.02 ),
78+ makeRow ("Squirtle" , "Water" , 241259 , 25.6 , 5.96 ),
79+ makeRow ("Blastoise" , "Water" , 162794 , 19.5 , 6.04 ),
80+ makeRow ("Charmander" , "Fire" , 265760 , 31.2 , 5.25 ),
81+ makeRow ("Charizard" , "Fire" , 567763 , 25.6 , 7.56 ),
6882 }).
6983 BorderRounded ().
7084 WithBaseStyle (styleBase ).
0 commit comments