Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config field use question's frontend id create dir. #17

Merged
merged 4 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Config: add `dir_with_frontend_id` field, when filled true use frontend id create dir.

## [0.9.3]

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool_to_int_with_if = "warn"

### restriction group
unwrap_used = "warn"
unwrap_in_result = "warn"
# unwrap_in_result = "warn"
semicolon_outside_block = "warn"
verbose_file_reads = "warn"
try_err = "warn"
Expand Down
119 changes: 28 additions & 91 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,119 +206,56 @@ session = ""

### CONFIG

运行 `lcode gencon -c` 生成配置,`lcode C` 编辑。

cn 用户建议更改两处: `url_suffix = "cn"`, `translate = true`.

```toml
# 是否显示翻译后的内容
translate = true
column = 4
num_sublist = 10
page_size = 25
editor = ["vim"]
lang = "rust"
code_dir = "/home/user/.local/share/lcode"
browser = ""

# 填入 `com` 或者 `cn`,来设置网站后缀 `leetcode.com` 或者 `leetcode.cn`
url_suffix = "cn"
```

### 各个字段的说明

查看 [Cookies 重要部分](#cookies-重要部分) 部分.

```toml
browser = false
```

填入 `false` 或者 `true` ,默认 `false`,`true` 会使用翻译后的内容显示题目详情。

```toml
translate = true
```

---

获取 `submissionlist` 时显示几列

```toml
# 获取 `submissionlist` 时显示几列
column = 4
```

---

显示最后多少条 `submissionlist` 信息

```toml
# 显示最后多少条 `submissionlist` 信息
num_sublist = 10
```

---

交互选择题目时一次显示几道题目

```toml
# 交互选择题目时一次显示几道题目
page_size = 25
```

---

填写你的编辑器,会尝试从环境变量 `EDITOR` 和 `VISUAL` 获取,
否则为 `vim`

魔法,使用这些编辑器或垂直分割问题和编辑器。

- vim
- nvim
- helix

```toml
# 填写你的编辑器,会尝试从环境变量 `EDITOR` 和 `VISUAL` 获取,
# 否则为 `vim`
#
# 魔法,使用这些编辑器或垂直分割问题和编辑器。
#
# - vim
# - nvim
# - helix
#
#可以在后面添加参数
#例如 `editor = ["vim", "--noplugin"]`
editor = ["vim"]
```

可以在后面添加参数

```toml
editor = ["vim", "--noplugin"]
```

---

设置你所选编程语言

```toml
# 设置你所选编程语言
lang = "rust"
```

---

设置代码和测试用例存储的位置

```toml
# 设置代码和测试用例存储的位置
# 也可以这样写,以`~`开头
# 例如: `code_dir = "~/.local/share/lcode"`
code_dir = "/home/user/.local/share/lcode"
```

也可以这样写,以`~`开头

```toml
code_dir = "~/.local/share/lcode"
```

---

填入 `com` 或者 `cn`,来设置网站后缀 `leetcode.com` 或者 `leetcode.cn`

```toml
url_suffix = "cn"
```

---

为了更好的写 rust。 这会添加一个 `Cargo.toml` 文件
# 查看 [Cookies 重要部分](#cookies-重要部分) 部分.
browser = ""

```toml
# 为了更好的写 rust。 这会添加一个 `Cargo.toml` 文件
cargo_integr = true
```

---
# 是否用 fronted id 创建代码目录
dir_with_frontend_id = true
```

## 用户信息

Expand Down
122 changes: 30 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,118 +224,56 @@ session = ""

### CONFIG

```toml
translate = false
column = 4
num_sublist = 10
page_size = 25
editor = ["vim"]
lang = "rust"
code_dir = "/home/user/.local/share/lcode"
browser = ""

url_suffix = "com"
```

### Here are the explanations for each field

Checkout the [Cookies (Important)](#cookies-important) section above.

```toml
browser = ""
```

---

Boolean, default is `false`. Show translated content or not.
Execute `lcode gencon` for create new cofnig and `lcode C` edit.

```toml
# Show translated content or not.
translate = false
```

---

When retrieving the **submissionlist**, how many columns should be displayed.
# Fill in `com` or `cn`, for set `leetcode.com` or `leetcode.cn`.
url_suffix = "com"

```toml
# When retrieving the **submissionlist**, how many columns should be displayed.
column = 4
```

---

How many recent entries of the submissionlist information should be displayed.

```toml
# How many recent entries of the submissionlist information should be displayed.
num_sublist = 10
```

---

How many questions should be displayed at once when interactively selecting a question.

```toml
# How many questions should be displayed at once when interactively selecting a question.
page_size = 25
```

---

Fill in your editor, it will attempt to retrieve it from
the environment variables `$EDITOR` and `$VISUAL`,
otherwise it will default to `vim`.

Specifically, when the editor is one of the ones below,
will vert split question and code.

- vim
- nvim
- helix

```toml
# Fill in your editor, it will attempt to retrieve it from
# the environment variables `$EDITOR` and `$VISUAL`,
# otherwise it will default to `vim`.
#
# Specifically, when the editor is one of the ones below,
# will vert split question and code.
#
# - vim
# - nvim
# - helix
#
# You can add additional parameters at the end.
# like `editor = ["vim", "--noplugin"]`
editor = ["vim"]
```

You can add additional parameters at the end.

```toml
editor = ["vim", "--noplugin"]
```

---

Set your selected programming language.

```toml
# Set your selected programming language.
lang = "rust"
```

---

Set the location for storing code and test cases.
You can also starting with `~`

```toml
# Set the location for storing code and test cases.
# You can also starting with `~`
# like `code_dir = "~/.local/share/lcode"`
code_dir = "/home/user/.local/share/lcode"
# or
code_dir = "~/.local/share/lcode"
```

---

Fill in `com` or `cn`, for set `leetcode.com` or `leetcode.cn`.

```toml
url_suffix = "com"
```

---

For better rust coding. It will add a `Cargo.toml` file
# Checkout the [Cookies (Important)](#cookies-important) section above.
browser = ""

```toml
# For better rust coding. It will add a `Cargo.toml` file
cargo_integr = true
```

## 👣The User Info
# use frontend id create code dir or not
dir_with_frontend_id = true
```

You can checkout the info/tab3 in tui for ensure cookies is valid.

Expand Down
47 changes: 25 additions & 22 deletions crates/lcode-config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{global, keymap::TuiKeyMap};
#[derive(PartialEq, Eq)]
#[derive(Serialize, Deserialize)]
#[derive(Default)]
pub struct User {
pub struct LcodeConfig {
#[serde(skip)]
pub urls: Urls,
#[serde(default)]
Expand All @@ -36,25 +36,27 @@ pub struct User {
#[derive(Serialize, Deserialize)]
pub struct Config {
#[serde(default)]
pub translate: bool,
pub translate: bool,
#[serde(default, with = "user_serializes")]
pub url_suffix: Suffix,
pub url_suffix: Suffix,
#[serde(default)]
pub column: usize,
pub column: usize,
#[serde(default)]
pub num_sublist: u32,
pub num_sublist: u32,
#[serde(default)]
pub page_size: usize,
pub page_size: usize,
#[serde(default = "default_editor")]
pub editor: VecDeque<String>,
pub editor: VecDeque<String>,
#[serde(default = "lang_default")]
pub lang: String,
pub lang: String,
#[serde(default = "default_code_dir")]
pub code_dir: PathBuf,
pub code_dir: PathBuf,
#[serde(default)]
pub browser: String,
pub browser: String,
#[serde(default = "cargo_default")]
pub cargo_integr: bool,
pub cargo_integr: bool,
#[serde(default = "default_ser_bool")]
pub dir_with_frontend_id: bool, // create qs dir use frontend id
}

impl Config {
Expand All @@ -73,21 +75,22 @@ impl Config {
impl Default for Config {
fn default() -> Self {
Self {
translate: false,
column: 4,
num_sublist: 16,
page_size: 25,
url_suffix: Suffix::default(),
editor: default_editor(),
lang: "rust".to_owned(),
code_dir: default_code_dir(),
browser: String::new(),
cargo_integr: true,
translate: false,
column: 4,
num_sublist: 16,
page_size: 25,
url_suffix: Suffix::default(),
editor: default_editor(),
lang: "rust".to_owned(),
code_dir: default_code_dir(),
browser: String::new(),
cargo_integr: true,
dir_with_frontend_id: false,
}
}
}

impl User {
impl LcodeConfig {
/// "cn" "en"
pub fn new(tongue: Suffix) -> Self {
let config = Config::new(tongue);
Expand Down
Loading