modularity

This commit is contained in:
Candifloss 2024-11-21 20:04:16 +05:30
parent 4f90edceef
commit 7ed36ce471
3 changed files with 136 additions and 27 deletions

102
.idea/workspace.xml Normal file
View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="ALL" />
</component>
<component name="CargoProjects">
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
</component>
<component name="ChangeListManager">
<list default="true" id="7404a252-decc-46ca-a3ce-8225afa42ca8" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="RsBuildProfile:dev" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MacroExpansionManager">
<option name="directoryName" value="6kwtndvm" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 2
}</component>
<component name="ProjectId" id="2kf6SCvTmKzhjLJnRhdDhchfDDs" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Cargo.Run prettyprompt.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.rust.reset.selective.auto.import": "true",
"git-widget-placeholder": "main",
"last_opened_file_path": "/home/lcm/Works/PrettyPrompt",
"node.js.detected.package.eslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
"org.rust.first.attach.projects": "true",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager" selected="Cargo.Run prettyprompt">
<configuration name="Run prettyprompt" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --package prettyprompt --bin prettyprompt" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<configuration name="Test prettyprompt" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="test --workspace" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>
<component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="7404a252-decc-46ca-a3ce-8225afa42ca8" name="Changes" comment="" />
<created>1723662281778</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1723662281778</updated>
<workItem from="1723662282995" duration="187000" />
<workItem from="1723662981939" duration="4684000" />
<workItem from="1725563638440" duration="7000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

31
src/indicators/path.rs Normal file
View File

@ -0,0 +1,31 @@
use std::env::{args, current_dir, var_os};
pub fn abrev_path(path: &str) -> String {
let mut short_dir = path.to_string();
let slashes = path.matches('/').count();
if slashes > 3 {
let parts: Vec<&str> = path.split('/').collect();
let len = parts.len() - 1;
let mut ch1: String;
for part in &parts[0..len] {
if part.to_string() != "" {
// to avoid the 1st "/"
ch1 = part.chars().next().expect(part).to_string(); // 1st char of each part
short_dir = short_dir.replace(part, &ch1);
}
}
}
short_dir
}
//pwd
pub fn homedir() -> String {
var_os("HOME")
.expect("UnknownDir")
.to_str()
.expect("UnknownDir")
.to_string()
}

View File

@ -5,32 +5,12 @@ use std::env::{args, current_dir, var_os};
mod indicators {
pub mod error;
pub mod git;
pub mod path;
pub mod shell;
pub mod ssh;
pub mod user;
}
use crate::indicators::{error::*, git::*, shell::*, ssh::*, user::*};
fn abrev_path(path: &str) -> String {
let mut short_dir = path.to_string();
let slashes = path.matches('/').count();
if slashes > 3 {
let parts: Vec<&str> = path.split('/').collect();
let len = parts.len() - 1;
let mut ch1: String;
for part in &parts[0..len] {
if part.to_string() != "" {
// to avoid the 1st "/"
ch1 = part.chars().next().expect(part).to_string(); // 1st char of each part
short_dir = short_dir.replace(part, &ch1);
}
}
}
short_dir
}
use crate::indicators::{error::*, git::*, path::*, shell::*, ssh::*, user::*};
fn main() -> std::io::Result<()> {
//let angle = "";
@ -53,11 +33,7 @@ fn main() -> std::io::Result<()> {
let git_char = get_git_char(&git_branch);
//pwd
let homedir = var_os("HOME")
.expect("UnknownDir")
.to_str()
.expect("UnknownDir")
.to_string();
let homedir = homedir();
let pwd = current_dir()?;
let mut cur_dir = pwd.display().to_string();
cur_dir = cur_dir.replace(&git_repo_root, ""); // Remove git repo root