filename truncation like in MC

English support forum

Moderators: Hacker, petermad, Stefan2, white

mrbeeye
Junior Member
Junior Member
Posts: 85
Joined: 2004-05-03, 02:56 UTC

filename truncation like in MC

Post by *mrbeeye »

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'
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6950
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp »

If the field is not long enough, you can hold the cursor over such a name and it will show you the full name and other details as popup.
Can be configured under the display options.
mrbeeye
Junior Member
Junior Member
Posts: 85
Joined: 2004-05-03, 02:56 UTC

Post by *mrbeeye »

Horst.Epp wrote:If the field is not long enough, you can hold the cursor over such a name and it will show you the full name and other details as popup.
Can be configured under the display options.
Why should I do it?
Filename truncation could be configured too.
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

Why should I do it?
Because it works ;-)
Filename truncation could be configured too.
If it worked ;-)
I switched to Linux, bye and thanks for all the fish!
mrbeeye
Junior Member
Junior Member
Posts: 85
Joined: 2004-05-03, 02:56 UTC

Post by *mrbeeye »

SanskritFritz wrote:If it worked ;-)
And why should not?

It's implemented in Midnight Commander 4.6, which is open-source.

It's nothing to do it: just look into MC sources and done!
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

It's nothing to do it: just look into MC sources and done!
Well, it might be only a matter of time until Christian implements it.
I switched to Linux, bye and thanks for all the fish!
mrbeeye
Junior Member
Junior Member
Posts: 85
Joined: 2004-05-03, 02:56 UTC

Post by *mrbeeye »

SanskritFritz wrote:Well, it might be only a matter of time until Christian implements it.
Yeah if somebody tells him about it.

And if he wants to implement it...
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

Excellent proposal, would like to see that, too.

Icfu
This account is for sale
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50386
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

It's nothing to do it: just look into MC sources and done!
Easy, but illegal - it's not allowed to use GPL sources in commercial software, and I take this very seriously.

How does MC handle the shortening of very long names WITHOUT spaces in them?
Author of Total Commander
https://www.ghisler.com
User avatar
pdavit
Power Member
Power Member
Posts: 1529
Joined: 2003-02-05, 21:41 UTC
Location: Kavala -> Greece -> Europe -> Earth -> Solar System -> Milky Way -> Space
Contact:

Post by *pdavit »

ghisler(Author) wrote:How does MC handle the shortening of very long names WITHOUT spaces in them?
Ahaa! You are showing some interest there. Cool! :P

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!!!
mrbeeye
Junior Member
Junior Member
Posts: 85
Joined: 2004-05-03, 02:56 UTC

Post by *mrbeeye »

ghisler(Author) wrote:Easy, but illegal - it's not allowed to use GPL sources in commercial software, and I take this very seriously.
That's not true, but then you'll have to release TC under GNU/GPL and many users would be very happy (believe me) :P

Why use GPL sources?; you can just inspire by it 8)
ghisler(Author) wrote:How does MC handle the shortening of very long names WITHOUT spaces in them?
Don't know, but I'll check.
I think MC just cut the "middle" of very long filename.

Aren't here any linux/bsd/unix... developers around to help us?
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

I think MC just cut the "middle" of very long filename.
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 switched to Linux, bye and thanks for all the fish!
mrbeeye
Junior Member
Junior Member
Posts: 85
Joined: 2004-05-03, 02:56 UTC

Post by *mrbeeye »

Taken from

Code: Select all

mc-2004-12-01-22.tar/mc-2004-12-01-22/src/util.c
Midnight Commander source snapshot.

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;
}
In Windows GUI, it will be more difficult.
One'll have to determine font metric of each character, count it...

Yeah SanskritFritz is right.
mrbeeye
Junior Member
Junior Member
Posts: 85
Joined: 2004-05-03, 02:56 UTC

Post by *mrbeeye »

Just wondering if this feature is denied.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Would be better -- I believe -- if we could get the current plugin interface extended to [ Name ] and [ Ext ], and then the community could provide this feature.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
Post Reply