Vaimer9 / vsh

A Unix shell written and implemented in rust 🦀
Mozilla Public License 2.0
93 stars 9 forks source link

[Draft] Custom theme #10

Closed MalauD closed 2 years ago

MalauD commented 2 years ago

So this is related to #9 since it will be useful for formatting git infos. Objectives:

Implementation idea: So first of all i had the idea of using a runtime formatting library such as mustache but it would cause problem for text coloring since these formater just replace and not color anything. So we have to implement our parser to do some token recognition. For that there is a library nom well known for parsing byte data and also string. With that in mind i had to think about a theme file syntax. Here is an example i had in mind:

&[#FF00FF]`[`{{home_dir}}`]`&[#00FF00]{{user_input}}

So

Anyway here is the current roadmap:

Vaimer9 commented 2 years ago

This is a very interesting idea and worth completing. Having separate files for theming would be extremely useful. Would really make the user's prompt their own. Although having a separate file may be overkill. Having a multiline string in toml might be somewhat similar

MalauD commented 2 years ago

Ok now you can test this it should be working. See: Config file:


[prompt]
theme="&[#7393B3]`[`{{current_dir}}`] `"

[misc]
alias = [
    ["", ""]
]

[effects]
underlined = false 
bold = true
dimmed = false
suggestion_color = "red"

truecolors = false 
true_suggestion_color = [255, 0, 0]

Result: Screenshot from 2022-02-26 16-00-36

Vaimer9 commented 2 years ago

Add the mpl-2 license headers

/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
Vaimer9 commented 2 years ago

Adding newline support would be usefull:

"&[#D8BFD8]{{username}}`@`{{hostname}}&[#7393B3]` `{{current_dir}}&[#FFFFFF]`$ `"

could be written down as:

"
&[#D8BFD8]{{username}}`@`{{hostname}}
&[#7393B3]` `{{current_dir}}
&[#FFFFFF]`$ `
"

Formatting would be better and would result in more readability

MalauD commented 2 years ago

Well you can you the newline character: \n

Vaimer9 commented 2 years ago

what I meant was that the \n character would be ignored if outside of the literal delimiters (i.e ``). As of now doing

theme = "`x`\n"

or:

theme = "`x`
"

both result in unwraps

MalauD commented 2 years ago

So that's because \n need to be inside the quote like any other string. For example: "&[#D8BFD8]{{username}}`@`{{hostname}}&[#7393B3]`\n`{{current_dir}}&[#FFFFFF]`$ `"

Vaimer9 commented 2 years ago

So that's because \n need to be inside the quote like any other string.

yes I know and I was requesting for it to be ignored if it is not inside the quote, that way the users can easily format their prompt as it grows larger in size

MalauD commented 2 years ago

Ok i understand i'will try to add that

MalauD commented 2 years ago

So know you can write your theme using multiple lines:

[prompt]
theme="""\
$[i]&[#D8BFD8]{{username}}`@`{{hostname}}$[c]&[#7393B3]` \
`{{current_dir}}&[#FFFFFF]`$ `\
"""