Dynamic value of the "-title: ..." cmd-line option

Разработка Far.
Post Reply
szabi
Posts: 2
Joined: Sun 30 Jun, 2019 22:17
Has thanked: 1 time

Dynamic value of the "-title: ..." cmd-line option

Post by szabi »

Hi,

In order for custom window titles to also benefit from the usual dynamic changes (like current panel dir, filename in viewer/editor etc.), I've added (in my local repo) a case-insensitive "%Title" placeholder to the "-title:..." command-line option, to represent the native FAR title string.

Just ~10 lines in 1 file; the diff page from my fork (%GitHub%/lunakid/FarManager/commit/f259ebfe16d79db471b29a1d4733bb2d8335b475.patch):

Code: Select all

From f259ebfe16d79db471b29a1d4733bb2d8335b475 Mon Sep 17 00:00:00 2001
From: Sz
Date: Sun, 30 Jun 2019 23:06:43 +0200
Subject: [PATCH] Allow reusing the original title in customized ones as "-title:Example %Title"

---
 far/constitle.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/far/constitle.cpp b/far/constitle.cpp
index 9ead50e60..96104d80f 100644
--- a/far/constitle.cpp
+++ b/far/constitle.cpp
@@ -104,6 +104,16 @@ static string& FarTitle()
 	return strFarTitle;
 }
 
+string CookTitle(string_view NewTitle)
+{
+	if (UserTitle().empty())
+		return NewTitle + GetFarTitleAddons();
+
+	string CustomizedTitle = UserTitle();
+	replace_icase(CustomizedTitle, L"%Title"sv, NewTitle);
+	return CustomizedTitle;
+}
+
 void ConsoleTitle::SetUserTitle(string_view const Title)
 {
 	UserTitle() = Title;
@@ -116,7 +126,7 @@ void ConsoleTitle::SetFarTitle(string_view const Title, bool Flush)
 	SCOPED_ACTION(std::lock_guard)(TitleCS);
 
 	FarTitle() = Title;
-	Global->ScrBuf->SetTitle(UserTitle().empty()? FarTitle() + GetFarTitleAddons() : UserTitle());
+	Global->ScrBuf->SetTitle(CookTitle(Title));
 	if (Flush)
 	{
 		Global->ScrBuf->Flush(flush_type::title);
Please note: I'm new here (but old FAR user), have read the FAQ (via G. Translate), had a look at "Wishes" in Mantis (mostly Russian, though), and a few other things I could find in English, incl. the Contrib. Guide at GitHub, which says a pull request would be OK. But I just don't feel confident enough "procedurally" yet (e.g. regarding the updates of various supplementary files, perhaps docs, build/version numbering etc. etc.), hence this post instead of a direct pull req.

If someone with the right "muscle memory" could copy-paste the change (and/or adjust as needed), that seems like the easiest way to me.
But any guidance is appreciated. Cheers!

Sz.
User avatar
DrKnS
Posts: 6114
Joined: Thu 04 Aug, 2005 06:44
Location: Kyiv
Has thanked: 12 times
Been thanked: 426 times

Dynamic value of the "-title: ..." cmd-line option

Post by DrKnS »

A pull request would be OK indeed.

The easiest way to find out what should be changed is to just have a look at some small existing commit.

In your case it would be nice to mention this new functionality in the command line help and in help files (if you don't know how to translate it to other languages - that's fine, just put the English text to other .hlf.m4 files).
And don't worry about missing something - we can discuss that in PR comments, suggest changes, and ultimately the one who will merge can first amend your commit to add anything that is missing.
szabi
Posts: 2
Joined: Sun 30 Jun, 2019 22:17
Has thanked: 1 time

Dynamic value of the "-title: ..." cmd-line option

Post by szabi »

Great, and thanks for your kind support, I'll get back to it later then.
Post Reply

Return to “Development”