fix style

pull/12/head
Takayuki Maeda 3 years ago
parent 1eb067c186
commit 3d4865a88e

@ -69,7 +69,7 @@ impl DatabasesComponent {
Span::styled(
name,
if selected {
Style::default().fg(Color::Magenta).bg(Color::Green)
Style::default().bg(Color::Blue)
} else {
Style::default()
},

@ -7,68 +7,56 @@ use sqlx::Row;
use unicode_width::UnicodeWidthStr;
pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> {
if true {
match key {
Key::Enter => {
app.query = app.input.drain(..).collect();
let re = Regex::new(r"select .+ from ([^ ]+).*").unwrap();
match re.captures(app.query.as_str()) {
Some(caps) => {
let mut rows =
sqlx::query(app.query.as_str()).fetch(app.pool.as_ref().unwrap());
let headers = sqlx::query(
format!("desc `{}`", caps.get(1).unwrap().as_str()).as_str(),
match key {
Key::Enter => {
app.query = app.input.drain(..).collect();
let re = Regex::new(r"select .+ from ([^ ]+).*").unwrap();
match re.captures(app.query.as_str()) {
Some(caps) => {
let mut rows =
sqlx::query(app.query.as_str()).fetch(app.pool.as_ref().unwrap());
let headers =
sqlx::query(format!("desc `{}`", caps.get(1).unwrap().as_str()).as_str())
.fetch_all(app.pool.as_ref().unwrap())
.await?
.iter()
.map(|table| table.get(0))
.collect::<Vec<String>>();
let mut records = vec![];
while let Some(row) = rows.try_next().await? {
records.push(
row.columns()
.iter()
.map(|col| convert_column_value_to_string(&row, col))
.collect::<Vec<String>>(),
)
.fetch_all(app.pool.as_ref().unwrap())
.await?
.iter()
.map(|table| table.get(0))
.collect::<Vec<String>>();
let mut records = vec![];
while let Some(row) = rows.try_next().await? {
records.push(
row.columns()
.iter()
.map(|col| convert_column_value_to_string(&row, col))
.collect::<Vec<String>>(),
)
}
app.record_table.headers = headers;
app.record_table.rows = records;
}
None => {
sqlx::query(app.query.as_str())
.execute(app.pool.as_ref().unwrap())
.await?;
}
app.record_table.reset(headers, records);
}
}
Key::Char(c) => app.input.push(c),
Key::Delete | Key::Backspace => {
if app.input.width() > 0 {
if app.input_cursor_x == 0 {
app.input.pop();
return Ok(());
}
if app.input.width() - app.input_cursor_x as usize > 0 {
app.input
.remove(app.input.width() - app.input_cursor_x as usize);
}
None => {
sqlx::query(app.query.as_str())
.execute(app.pool.as_ref().unwrap())
.await?;
}
}
Key::Left => app.decrement_input_cursor_x(),
Key::Right => app.increment_input_cursor_x(),
Key::Esc => app.focus_block = FocusBlock::Query,
_ => {}
}
} else {
match key {
Key::Char('h') => app.focus_block = FocusBlock::DabataseList,
Key::Char('j') => app.focus_block = FocusBlock::RecordTable,
Key::Char('c') => app.focus_block = FocusBlock::ConnectionList,
Key::Enter => app.focus_block = FocusBlock::Query,
_ => (),
Key::Char(c) => app.input.push(c),
Key::Delete | Key::Backspace => {
if app.input.width() > 0 {
if app.input_cursor_x == 0 {
app.input.pop();
return Ok(());
}
if app.input.width() - app.input_cursor_x as usize > 0 {
app.input
.remove(app.input.width() - app.input_cursor_x as usize);
}
}
}
Key::Left => app.decrement_input_cursor_x(),
Key::Right => app.increment_input_cursor_x(),
Key::Esc => app.focus_block = FocusBlock::DabataseList,
_ => {}
}
Ok(())
}

@ -4,8 +4,12 @@ use crate::event::Key;
pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> {
match key {
Key::Char('h') => app.record_table.previous_column(),
Key::Char('j') => app.record_table.next(),
Key::Char('k') => app.record_table.previous(),
Key::Char('j') => app.record_table.next(1),
Key::Ctrl('d') => app.record_table.next(10),
Key::Char('k') => app.record_table.previous(1),
Key::Ctrl('u') => app.record_table.previous(10),
Key::Char('g') => app.record_table.scroll_top(),
Key::Shift('G') | Key::Shift('g') => app.record_table.scroll_bottom(),
Key::Char('l') => app.record_table.next_column(),
Key::Left => app.focus_block = FocusBlock::DabataseList,
Key::Char('c') => app.focus_block = FocusBlock::ConnectionList,

@ -6,6 +6,9 @@ mod ui;
mod user_config;
mod utils;
#[macro_use]
mod log;
use crate::app::{App, FocusBlock};
use crate::event::{Event, Key};
use crate::handlers::handle_app;
@ -21,6 +24,8 @@ use tui::{backend::CrosstermBackend, Terminal};
async fn main() -> anyhow::Result<()> {
enable_raw_mode()?;
outln!("gobang logger");
let user_config = user_config::UserConfig::new("sample.toml").ok();
let mut stdout = stdout();

@ -24,14 +24,14 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
.iter()
.map(|i| {
ListItem::new(vec![Spans::from(Span::raw(i.database_url()))])
.style(Style::default().fg(Color::White))
.style(Style::default())
})
.collect();
let tasks = List::new(connections)
.block(Block::default().borders(Borders::ALL).title("Connections"))
.highlight_style(Style::default().fg(Color::Green))
.highlight_style(Style::default().bg(Color::Blue))
.style(match app.focus_block {
FocusBlock::ConnectionList => Style::default().fg(Color::Green),
FocusBlock::ConnectionList => Style::default(),
_ => Style::default().fg(Color::DarkGray),
});
let popup_layout = Layout::default()
@ -76,14 +76,13 @@ pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) -> anyhow::Result<(
let table_status: Vec<ListItem> = app
.table_status()
.iter()
.map(|i| {
ListItem::new(vec![Spans::from(Span::raw(i.to_string()))])
.style(Style::default().fg(Color::White))
})
.map(|i| ListItem::new(vec![Spans::from(Span::raw(i.to_string()))]).style(Style::default()))
.collect();
let tasks = List::new(table_status)
.block(Block::default().borders(Borders::ALL))
.highlight_style(Style::default().fg(Color::Green));
let tasks = List::new(table_status).block(
Block::default()
.borders(Borders::ALL)
.style(Style::default().fg(Color::DarkGray)),
);
f.render_widget(tasks, left_chunks[1]);
let right_chunks = Layout::default()
@ -145,7 +144,7 @@ fn draw_structure_table<B: Backend>(
let headers = app.structure_table.headers();
let header_cells = headers
.iter()
.map(|h| Cell::from(h.to_string()).style(Style::default().fg(Color::White)));
.map(|h| Cell::from(h.to_string()).style(Style::default()));
let header = Row::new(header_cells).height(1).bottom_margin(1);
let rows = app.structure_table.rows();
let rows = rows.iter().map(|item| {
@ -157,7 +156,7 @@ fn draw_structure_table<B: Backend>(
+ 1;
let cells = item
.iter()
.map(|c| Cell::from(c.to_string()).style(Style::default().fg(Color::White)));
.map(|c| Cell::from(c.to_string()).style(Style::default()));
Row::new(cells).height(height as u16).bottom_margin(1)
});
let widths = (0..10)
@ -166,7 +165,7 @@ fn draw_structure_table<B: Backend>(
let t = Table::new(rows)
.header(header)
.block(Block::default().borders(Borders::ALL).title("Structure"))
.highlight_style(Style::default().fg(Color::Green))
.highlight_style(Style::default().bg(Color::Blue))
.style(match app.focus_block {
FocusBlock::RecordTable => Style::default(),
_ => Style::default().fg(Color::DarkGray),

Loading…
Cancel
Save