ui.rs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. use crate::view::View;
  2. use log::debug;
  3. use tui::{
  4. backend::Backend,
  5. layout::{Constraint, Direction, Layout, Rect},
  6. style::Style,
  7. text::{Span, Spans},
  8. widgets::{Block, Borders, List, ListItem, Paragraph},
  9. Frame,
  10. };
  11. pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
  12. let list_margin = 2;
  13. let list_direction = Direction::Horizontal;
  14. let list_cnstrnts = vec![Constraint::Percentage(50), Constraint::Percentage(50)];
  15. let mut nodes = Vec::new();
  16. let style = Style::default();
  17. // lines.push(sublist)
  18. // either have one hashmap w value as enum or have type info in hashset
  19. for id in &view.id_list.node_id {
  20. let id_span = Span::raw(id.to_string());
  21. let mut lines = vec![Spans::from(id_span)];
  22. // create a new vector of addresses
  23. // render as a sub node
  24. match &view.info_list.infos.get(id) {
  25. Some(node) => {
  26. //if !node.outbound.iter().all(|node| node.is_empty) {
  27. // lines.push(Spans::from(Span::styled(" Outgoing", Style::default())));
  28. //}
  29. //for outbound in &node.outbound.clone() {
  30. // for slot in outbound.slots.clone() {
  31. // let addr = Span::styled(format!(" {}", slot.addr), style);
  32. // let msg: Span = match slot.channel.last_status.as_str() {
  33. // "recv" => Span::styled(
  34. // format!(" [R: {}]", slot.channel.last_msg),
  35. // style,
  36. // ),
  37. // "sent" => Span::styled(
  38. // format!(" [S: {}]", slot.channel.last_msg),
  39. // style,
  40. // ),
  41. // a => Span::styled(a.to_string(), style),
  42. // };
  43. // lines.push(Spans::from(vec![addr, msg]));
  44. // }
  45. //}
  46. //if !node.inbound.iter().all(|node| node.is_empty) {
  47. // lines.push(Spans::from(Span::styled(" Incoming", Style::default())));
  48. //}
  49. //for inbound in &node.inbound {
  50. // let addr = Span::styled(format!(" {}", inbound.connected), style);
  51. // let msg: Span = match inbound.channel.last_status.as_str() {
  52. // "recv" => Span::styled(
  53. // format!(" [R: {}]", inbound.channel.last_msg),
  54. // style,
  55. // ),
  56. // "sent" => Span::styled(
  57. // format!(" [R: {}]", inbound.channel.last_msg),
  58. // style,
  59. // ),
  60. // a => Span::styled(a.to_string(), style),
  61. // };
  62. // lines.push(Spans::from(vec![addr, msg]));
  63. //}
  64. //lines.push(Spans::from(Span::styled(" Manual", Style::default())));
  65. //for connect in &node.manual {
  66. // lines.push(Spans::from(Span::styled(format!(" {}", connect.key), style)));
  67. //}
  68. }
  69. None => {
  70. // TODO
  71. debug!("This is also a bug");
  72. }
  73. }
  74. let ids = ListItem::new(lines);
  75. nodes.push(ids);
  76. }
  77. let nodes =
  78. List::new(nodes).block(Block::default().borders(Borders::ALL)).highlight_symbol(">> ");
  79. let slice = Layout::default()
  80. .direction(list_direction)
  81. .margin(list_margin)
  82. .constraints(list_cnstrnts)
  83. .split(f.size());
  84. f.render_stateful_widget(nodes, slice[0], &mut view.id_list.state);
  85. render_info_right(view.clone(), f, slice);
  86. }
  87. fn render_info_right<B: Backend>(_view: View, f: &mut Frame<'_, B>, slice: Vec<Rect>) {
  88. let span = vec![];
  89. let graph =
  90. Paragraph::new(span).block(Block::default().borders(Borders::ALL)).style(Style::default());
  91. f.render_widget(graph, slice[1]);
  92. }