#leetcode #tui #algorithm #fuzzy-search #questions #testing #terminal

bin+lib lcode

An application of terminal write leetcode.一个终端刷力扣的应用

23 unstable releases (3 breaking)

new 0.7.18 Apr 22, 2024
0.7.13 Mar 29, 2024
0.6.1 Dec 2, 2023
0.6.0 Nov 14, 2023

#94 in Asynchronous

Download history 15/week @ 2024-01-10 3/week @ 2024-01-31 77/week @ 2024-02-14 258/week @ 2024-02-21 184/week @ 2024-02-28 59/week @ 2024-03-06 12/week @ 2024-03-13 364/week @ 2024-03-20 277/week @ 2024-03-27 144/week @ 2024-04-03 48/week @ 2024-04-10 360/week @ 2024-04-17

851 downloads per month

Apache-2.0 and LGPL-3.0-or-later

295KB
7.5K SLoC

Brush leetcode under the terminal

🪶Features

  • Open the editor of your choice for editing.
  • Filter based on the category of the question.
  • Fuzzy search.
  • Test and submit the code.
  • Modify the test case.
  • Automatically get cookies to eliminate the need for manual copying from the browser, power by decrypt-cookies.

💄Install

dependencies:

  • libsecret (Linux Optional)
  • libdbus (Linux notify)
  • mdcat (render markdown)

build-dependencies:

  • gcc
  • pkg-config (when without cross feature)
  • libdbus-1-dev (when without cross feature)

You can use any of the following methods to install

[!NOTE]

add ~/.cargo/bin to your $PATH

cargo binstall lcode

In reality, cargo-binstall is used to download binaries from release

  • Build by yourself
rustup default nightly
cargo install --locked --force lcode
# or
# cargo install --features cross --locked --force lcode

Update lcode

use cargo-update

cargo install-update --all

🔧Usage

Generate configuration, manual modification of the configuration is also possible, and it will be automatically generated at runtime. Without -c, it will be generated in English.

lcode gencon -c

Synchronize basic data first.

lcode S

View the documentation for assistance.

lcode -h

Begin selecting a question.

lcode fzy <edit>

📼Videos

https://github.com/saying121/leetcode-cn-en-cli/assets/74663483/57a633e5-6bae-4816-a224-d7d61d2141af

https://github.com/saying121/leetcode-cn-en-cli/assets/74663483/9ad6ad58-b401-42f6-b8dc-359f78a37729

⚙️Configuration

The configuration located

  • Linux: ~/.config/leetcode-cn-en-cli/
  • macos: ~/.config/leetcode-cn-en-cli/
  • Windows: C:\Users\user\AppData\Roaming\leetcode-cn-en-cli

The code default located

  • Linux: ~/.local/share/leetcode-cn-en-cli/
  • macOS: ~/Library/Application Support/leetcode-cn-en-cli
  • Windows: C:\Users\user\AppData\Local\leetcode-cn-en-cli

code layout: default

The cache located

  • Linux: ~/.local/share/leetcode-cn-en-cli/
  • macOS: ~/Library/Caches/leetcode-cn-en-cli
  • Windows: C:\Users\user\AppData\Local\leetcode-cn-en-cli

Cookies (Important)

[First, login leetcode in browser for generate cookies]

General you just need filled browser at ~/.config/leetcode-cn-en-cli/config.toml.

When use the section,be careful not to clear cookies when closing the browser.

browser = "edge" # `chrome`, `edge`, `firefox`, `librewolf` etc.
# Not casesensitive, `eDgE` also ok.

The detail: decrypt-cookies


~/.config/leetcode-cn-en-cli/cookies.toml

csrf = ""
session = ""

[cookies] section

  • If the two fields are not empty, use the content filled by the user. And not use other method to get cookies。

    • Fill in manually:

      Press F12 on the browser's leetcode.com/com page, click network. Find the Cookie field, copy the csrftoken=<$content>; and LEETCODE_SESSION=<$content>; copy the $content into the configuration.

  • If filled browser , will try to use the browser to get cookies.

  • If neither of the above two items is filled in, and then use this order Firefox -> Librewolf -> Chrome -> Edge -> Chromium -> Brave -> Yandex -> Vivaldi -> Opera -> OperaGX -> CocCoc try to get cookies.

Keymap

keymap

LANGS

langs

CONFIG

translate = false
column = 4
num_sublist = 10
page_size = 25
editor = ["vim"]
lang = "rust"
code_dir = "/home/user/.local/share/leetcode-cn-en-cli"
browser = ""

url_suffix = "com"

Here are the explanations for each field

Checkout the Cookies (Important) section above.

browser = ""

Boolean, default is false. Show translated content or not.

translate = false

When retrieving the submissionlist, how many columns should be displayed.

column = 4

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.

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
editor = ["vim"]

You can add additional parameters at the end.

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

Set your selected programming language.

lang = "rust"

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

code_dir = "/home/user/.local/share/leetcode-cn-en-cli"
# or
code_dir = "~/.local/share/leetcode-cn-en-cli"

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

url_suffix = "com"

For better rust coding. It will add a Cargo.toml file

cargo_integr = true

👣 The User Infos

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

Todo

  • cache cookies

Dependencies

~54–94MB
~1.5M SLoC