Skip to content

Commit

Permalink
Allow swapping the positions of the fields
Browse files Browse the repository at this point in the history
Allow swapping the positions of the fields
  • Loading branch information
vyfor authored Apr 15, 2024
2 parents 59d5b63 + fd8efa4 commit f944044
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ require('cord').setup({
show_time = true, -- Display start timestamp
show_repository = true, -- Display 'View repository' button linked to repository url, if any
show_cursor_position = true, -- Display line and column number of cursor's position
swap_fields = false, -- If enabled, workspace is displayed first
},
lsp = {
show_problem_count = false, -- Display number of diagnostics problems
Expand Down
4 changes: 3 additions & 1 deletion lua/cord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cord.config = {
show_time = true,
show_repository = true,
show_cursor_position = false,
swap_fields = false,
},
lsp = {
show_problem_count = false,
Expand Down Expand Up @@ -67,7 +68,8 @@ local function connect(config)
config.text.editing,
config.text.file_browser,
config.text.plugin_manager,
config.text.workspace
config.text.workspace,
config.display.swap_fields
)
end

Expand Down
3 changes: 2 additions & 1 deletion lua/cord/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ local function init_discord(ffi)
const char* editingText,
const char* fileBrowserText,
const char* pluginManagerText,
const char* workspaceText
const char* workspaceText,
bool swap
);
bool update_presence(
const char* filename,
Expand Down
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const GITHUB_ASSETS_URL: &str =
static mut RICH_CLIENT: Option<RichClient> = None;
static mut CLIENT_IMAGE: String = String::new();
static mut CWD: Option<String> = None;
static mut SWAP_FIELDS: bool = false;
static mut START_TIME: Option<u128> = None;
static mut EDITOR_TOOLTIP: String = String::new();
static mut IDLE_TEXT: String = String::new();
Expand All @@ -49,6 +50,7 @@ pub extern "C" fn init(
file_browser_text: *const c_char,
plugin_manager_text: *const c_char,
workspace_text: *const c_char,
swap_fields: bool,
) {
unsafe {
if INITIALIZED {
Expand Down Expand Up @@ -90,6 +92,7 @@ pub extern "C" fn init(
FILE_BROWSER_TEXT = ptr_to_string(file_browser_text);
PLUGIN_MANAGER_TEXT = ptr_to_string(plugin_manager_text);
WORKSPACE_TEXT = ptr_to_string(workspace_text);
SWAP_FIELDS = swap_fields;

std::thread::spawn(move || {
if let Ok(mut client) = RichClient::connect(client_id) {
Expand Down Expand Up @@ -210,22 +213,29 @@ pub extern "C" fn update_presence(
}
};
let mut activity = Activity {
details: Some(presence_details),
..Default::default()
};
let mut state = None;
if let Some(cwd) = CWD.as_ref() {
if !WORKSPACE_TEXT.is_empty() {
activity.state = Some(if problem_count != -1 {
state = Some(if problem_count != -1 {
format!(
"{} - {} problems",
WORKSPACE_TEXT.replace("{}", &cwd),
problem_count
)
} else {
WORKSPACE_TEXT.replace("{}", &cwd)
})
});
}
}
if SWAP_FIELDS {
activity.state = Some(presence_details);
activity.details = state;
} else {
activity.state = state;
activity.details = Some(presence_details);
}
activity.assets = Some(ActivityAssets {
large_image: Some(presence_large_image),
large_text: Some(presence_large_text.to_string()),
Expand Down

0 comments on commit f944044

Please sign in to comment.