filename truncation like in MC
Moderators: Hacker, petermad, Stefan2, white
filename truncation like in MC
What about the filename truncation like in Midnight Commander 4.6?
So:
this is long very very very very long file name.ext
will be
this is long very very ~ name.ext
It's essential (at least for me) to see the beginning and ending of filename.
See picture: Image: http://geek.ucm.sk/~mrbeeye/dl/truncation.jpg
The full name is: 'jason m. cluts-groundswell (mrbeeye remix).ogg'
So:
this is long very very very very long file name.ext
will be
this is long very very ~ name.ext
It's essential (at least for me) to see the beginning and ending of filename.
See picture: Image: http://geek.ucm.sk/~mrbeeye/dl/truncation.jpg
The full name is: 'jason m. cluts-groundswell (mrbeeye remix).ogg'
- SanskritFritz
- Power Member
- Posts: 3693
- Joined: 2003-07-24, 09:25 UTC
- Location: Budapest, Hungary
- SanskritFritz
- Power Member
- Posts: 3693
- Joined: 2003-07-24, 09:25 UTC
- Location: Budapest, Hungary
- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Easy, but illegal - it's not allowed to use GPL sources in commercial software, and I take this very seriously.It's nothing to do it: just look into MC sources and done!
How does MC handle the shortening of very long names WITHOUT spaces in them?
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
- pdavit
- Power Member
- Posts: 1529
- Joined: 2003-02-05, 21:41 UTC
- Location: Kavala -> Greece -> Europe -> Earth -> Solar System -> Milky Way -> Space
- Contact:
Ahaa! You are showing some interest there. Cool!ghisler(Author) wrote:How does MC handle the shortening of very long names WITHOUT spaces in them?

It would be nice to have this feature provided it is customizable somehow to also keep the current method.
"My only reason for still using M$ Window$ as an OS is the existence of Total Commander!"
Christian Ghisler Rules!!!
Christian Ghisler Rules!!!
That's not true, but then you'll have to release TC under GNU/GPL and many users would be very happy (believe me)ghisler(Author) wrote:Easy, but illegal - it's not allowed to use GPL sources in commercial software, and I take this very seriously.

Why use GPL sources?; you can just inspire by it

Don't know, but I'll check.ghisler(Author) wrote:How does MC handle the shortening of very long names WITHOUT spaces in them?
I think MC just cut the "middle" of very long filename.
Aren't here any linux/bsd/unix... developers around to help us?
- SanskritFritz
- Power Member
- Posts: 3693
- Joined: 2003-07-24, 09:25 UTC
- Location: Budapest, Hungary
That shouldnt be enough for TC, because MC uses fixed width fonts on a fixed lenght, while TC uses variable width font, and even the lenght of the available space varies, depending on the space available on the right. So just cutting the filename on certain position is not enough, TC has to determine the space in pixels (or whatever), calculate the length of the filename in pixels (or whatever), and cut accordingly, considering the width of the characters at the cut.I think MC just cut the "middle" of very long filename.
I switched to Linux, bye and thanks for all the fish!
Taken from Midnight Commander source snapshot.
between /** **/ are my comments
In Windows GUI, it will be more difficult.
One'll have to determine font metric of each character, count it...
Yeah SanskritFritz is right.
Code: Select all
mc-2004-12-01-22.tar/mc-2004-12-01-22/src/util.c
between /** **/ are my comments

Code: Select all
/*
* Remove the middle part of the string to fit given length.
* Use "~" to show where the string was truncated.
* Return static buffer, no need to free() it.
*/
const char *
name_trunc (const char *txt, int trunc_len)
{
static char x[MC_MAXPATHLEN + MC_MAXPATHLEN];
int txt_len;
char *p;
/** if filename length threshold is bigger than MAXPATHLEN (= 8192 or 2048) then shorten it **/
if ((size_t) trunc_len > sizeof (x) - 1) {
trunc_len = sizeof (x) - 1;
}
/** the length of very long filename **/
txt_len = strlen (txt);
/** if length of very long filename is lower than threshold then just copy
very long filename into x (which will be returned as return-value)
**/
if (txt_len <= trunc_len) {
strcpy (x, txt);
}
/** if not **/
else {
/** count the middle of very long filename **/
int y = (trunc_len / 2) + (trunc_len % 2);
/** copy the first half of very long filename into x **/
strncpy (x, txt, y);
/** copy the second "half" of very long filename into x behind the first half + 1 **/
strncpy (x + y, txt + txt_len - (trunc_len / 2), trunc_len / 2);
/** insert '~' char into the middle of very long filename **/
x[y] = '~';
}
/** we have null terminated strings in C/C++ **/
x[trunc_len] = 0;
/** if character is printable do nothing else exchange with '?' character **/
for (p = x; *p; p++)
if (!is_printable (*p)) *p = '?';
/** return truncated very long filename **/
return x;
}
One'll have to determine font metric of each character, count it...
Yeah SanskritFritz is right.
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC