Skip to content

Commit

Permalink
datatree -> tree and gobang -> zhobo
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoto7250 committed Jun 16, 2024
1 parent 7b1b5f7 commit 046c367
Show file tree
Hide file tree
Showing 33 changed files with 90 additions and 172 deletions.
71 changes: 31 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
[package]
name = "gobang"
name = "zhobo"
version = "0.1.0-alpha.5"
authors = ["Takayuki Maeda <takoyaki0316@gmail.com>"]
authors = ["Kyoto7250 <kyoto7250@aol.com>"]
edition = "2018"
license = "MIT"
homepage = "https://github.com/TaKO8Ki/gobang"
repository = "https://github.com/TaKO8Ki/gobang"
homepage = "https://github.com/kyoto7250/zhobo"
repository = "https://github.com/kyoto7250/zhobo"
readme = "README.md"
description = "A cross-platform TUI database management tool written in Rust"
exclude = ["resources/"]

[workspace]
members=[
"database-tree"
]

[dependencies]
tui = { version = "0.15.0", features = ["crossterm"], default-features = false }
crossterm = "0.20"
Expand All @@ -25,11 +20,11 @@ chrono = "0.4"
tokio = { version = "1.11.0", features = ["full"] }
futures = "0.3.5"
serde_json = "1.0"
thiserror = "1.0"
serde = "1.0"
toml = "0.4"
strum = "0.21"
strum_macros = "0.21"
database-tree = { path = "./database-tree", version = "0.1.0-alpha.5" }
easy-cast = "0.4"
async-trait = "0.1.50"
itertools = "0.10.0"
Expand Down
15 changes: 0 additions & 15 deletions database-tree/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion database-tree/README.md

This file was deleted.

16 changes: 8 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::clipboard::copy_to_clipboard;
use crate::components::{
CommandInfo, Component as _, DrawableComponent as _, EventState, StatefulDrawableComponent,
};
use crate::database::{MySqlPool, Pool, PostgresPool, SqlitePool, RECORDS_LIMIT_PER_PAGE};
use crate::event::Key;
use crate::{
components::tab::Tab,
components::{
tab::Tab,
{
command, ConnectionsComponent, DatabasesComponent, ErrorComponent, HelpComponent,
PropertiesComponent, RecordTableComponent, SqlEditorComponent, TabComponent,
},
config::Config,
};
use crate::components::{
CommandInfo, Component as _, DrawableComponent as _, EventState, StatefulDrawableComponent,
};
use crate::config::Config;
use crate::database::{MySqlPool, Pool, PostgresPool, SqlitePool, RECORDS_LIMIT_PER_PAGE};
use crate::event::Key;
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use structopt::StructOpt;

/// A cross-platform TUI database management tool written in Rust
#[derive(StructOpt, Debug)]
#[structopt(name = "gobang")]
#[structopt(name = "zhobo")]
pub struct Cli {
#[structopt(flatten)]
pub config: CliConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/components/database_filter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{compute_character_width, Component, DrawableComponent, EventState};
use crate::components::command::CommandInfo;
use crate::event::Key;
use crate::tree::Table;
use anyhow::Result;
use database_tree::Table;
use tui::{
backend::Backend,
layout::Rect,
Expand Down
6 changes: 3 additions & 3 deletions src/components/databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::components::command::{self, CommandInfo};
use crate::config::{Connection, KeyConfig};
use crate::database::Pool;
use crate::event::Key;
use crate::tree::{Database, DatabaseTree, DatabaseTreeItem};
use crate::ui::common_nav;
use crate::ui::scrolllist::draw_list_block;
use anyhow::Result;
use database_tree::{Database, DatabaseTree, DatabaseTreeItem};
use std::collections::BTreeSet;
use std::convert::From;
use tui::{
Expand Down Expand Up @@ -275,10 +275,10 @@ fn tree_nav(tree: &mut DatabaseTree, key: Key, key_config: &KeyConfig) -> bool {
#[cfg(test)]
mod test {
use super::{Color, Database, DatabaseTreeItem, DatabasesComponent, Span, Spans, Style};
use database_tree::Table;
use crate::tree::Table;

#[test]
fn test_tree_database_tree_item_to_span() {
fn test_tree_tree_item_to_span() {
const WIDTH: u16 = 10;
assert_eq!(
DatabasesComponent::tree_item_to_span(
Expand Down
4 changes: 2 additions & 2 deletions src/components/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl DrawableComponent for HelpComponent {

f.render_widget(
Paragraph::new(Spans::from(vec![Span::styled(
format!("gobang {}", Version::new()),
format!("zhobo {}", Version::new()),
Style::default(),
)]))
.alignment(Alignment::Right),
Expand Down Expand Up @@ -151,7 +151,7 @@ impl HelpComponent {
processed += 1;

txt.push(Spans::from(Span::styled(
format!(" {}{:w$}", command_info.text.name, w = width),
format!(" {}{w:w$}", command_info.text.name, w = width),
if is_selected {
Style::default().bg(Color::Blue)
} else {
Expand Down
24 changes: 1 addition & 23 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod utils;
#[cfg(debug_assertions)]
pub mod debug;

pub use command::{CommandInfo, CommandText};
pub use command::CommandInfo;
pub use completion::CompletionComponent;
pub use connections::ConnectionsComponent;
pub use database_filter::DatabaseFilterComponent;
Expand All @@ -34,9 +34,6 @@ pub use table_filter::TableFilterComponent;
pub use table_status::TableStatusComponent;
pub use table_value::TableValueComponent;

#[cfg(debug_assertions)]
pub use debug::DebugComponent;

use crate::database::Pool;
use anyhow::Result;
use async_trait::async_trait;
Expand Down Expand Up @@ -100,30 +97,11 @@ pub trait Component {
Ok(EventState::NotConsumed)
}

fn focused(&self) -> bool {
false
}

fn focus(&mut self, _focus: bool) {}

fn is_visible(&self) -> bool {
true
}

fn hide(&mut self) {}

fn show(&mut self) -> Result<()> {
Ok(())
}

fn toggle_visible(&mut self) -> Result<()> {
if self.is_visible() {
self.hide();
Ok(())
} else {
self.show()
}
}
}

fn compute_character_width(c: char) -> u16 {
Expand Down
10 changes: 5 additions & 5 deletions src/components/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::components::TableComponent;
use crate::config::KeyConfig;
use crate::database::Pool;
use crate::event::Key;
use crate::tree::{Database, Table};
use anyhow::Result;
use async_trait::async_trait;
use database_tree::{Database, Table};
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
Expand Down Expand Up @@ -74,7 +74,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
columns.get(0).unwrap().fields(),
columns.first().unwrap().fields(),
database.clone(),
table.clone(),
);
Expand All @@ -87,7 +87,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
constraints.get(0).unwrap().fields(),
constraints.first().unwrap().fields(),
database.clone(),
table.clone(),
);
Expand All @@ -100,7 +100,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
foreign_keys.get(0).unwrap().fields(),
foreign_keys.first().unwrap().fields(),
database.clone(),
table.clone(),
);
Expand All @@ -113,7 +113,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
indexes.get(0).unwrap().fields(),
indexes.first().unwrap().fields(),
database.clone(),
table.clone(),
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/record_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::components::command::CommandInfo;
use crate::components::{TableComponent, TableFilterComponent};
use crate::config::KeyConfig;
use crate::event::Key;
use crate::tree::{Database, Table as DTable};
use anyhow::Result;
use database_tree::{Database, Table as DTable};
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
Expand Down
2 changes: 1 addition & 1 deletion src/components/sql_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Component for SqlEditorComponent {
key if matches!(self.focus, Focus::Table) => return self.table.event(key),
_ => (),
}
return Ok(EventState::NotConsumed);
Ok(EventState::NotConsumed)
}

async fn async_event(&mut self, key: Key, pool: &Box<dyn Pool>) -> Result<EventState> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use super::{
use crate::components::command::{self, CommandInfo};
use crate::config::KeyConfig;
use crate::event::Key;
use crate::tree::{Database, Table as DTable};
use anyhow::Result;
use database_tree::{Database, Table as DTable};
use std::convert::From;
use tui::{
backend::Backend,
Expand Down
6 changes: 2 additions & 4 deletions src/components/table_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use super::{
use crate::components::command::CommandInfo;
use crate::config::KeyConfig;
use crate::event::Key;
use crate::tree::Table;
use anyhow::Result;
use database_tree::Table;
use tui::{
backend::Backend,
layout::Rect,
Expand Down Expand Up @@ -163,9 +163,7 @@ impl StatefulDrawableComponent for TableFilterComponent {
(self
.table
.as_ref()
.map_or(String::new(), |table| {
format!("{} ", table.name.to_string())
})
.map_or(String::new(), |table| format!("{} ", table.name))
.width() as u16)
.saturating_add(self.input_cursor_position),
0,
Expand Down
2 changes: 1 addition & 1 deletion src/components/table_status.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{Component, DrawableComponent, EventState};
use crate::components::command::CommandInfo;
use crate::event::Key;
use crate::tree::Table;
use anyhow::Result;
use database_tree::Table;
use tui::{
backend::Backend,
layout::Rect,
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub fn get_app_config_path() -> anyhow::Result<std::path::PathBuf> {
}
.ok_or_else(|| anyhow::anyhow!("failed to find os config dir."))?;

path.push("gobang");
path.push("zhobo");
std::fs::create_dir_all(&path)?;
Ok(path)
}
Expand Down
Loading

0 comments on commit 046c367

Please sign in to comment.