aboutsummaryrefslogtreecommitdiffhomepage
path: root/highlight.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-17 18:08:08 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-18 18:51:11 -0800
commit1bedc16544fb28892704f01195ebd4dd90dd1fbb (patch)
treecd986e679006cd879f6c29127fd463f219f8ceca /highlight.cpp
parentac0b97a571e4a93c2aa8232b3df1ac8cc7f1f361 (diff)
Enhanced directory detection in a way we don't actually need yet
Diffstat (limited to 'highlight.cpp')
-rw-r--r--highlight.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/highlight.cpp b/highlight.cpp
index 1f34cd4c..4ca9843f 100644
--- a/highlight.cpp
+++ b/highlight.cpp
@@ -66,11 +66,12 @@ static const wchar_t * const highlight_var[] =
/**
Tests if the specified string is the prefix of any valid path in the system.
-
+
+ \require_dir Whether the valid path must be a directory
\return zero it this is not a valid prefix, non-zero otherwise
*/
// PCA DOES_IO
-static bool is_potential_path( const wcstring &cpath )
+static bool is_potential_path( const wcstring &cpath, bool require_dir = false )
{
ASSERT_IS_BACKGROUND_THREAD();
@@ -121,12 +122,11 @@ static bool is_potential_path( const wcstring &cpath )
}
- if( !has_magic && cleaned_path.length() )
+ if( !has_magic && ! cleaned_path.empty() )
{
- int must_be_dir = 0;
+ bool must_be_full_dir = cleaned_path[cleaned_path.length()-1] == L'/';
DIR *dir;
- must_be_dir = cleaned_path[cleaned_path.length()-1] == L'/';
- if( must_be_dir )
+ if( must_be_full_dir )
{
dir = wopendir( cleaned_path );
res = !!dir;
@@ -147,9 +147,10 @@ static bool is_potential_path( const wcstring &cpath )
else if( (dir = wopendir( dir_name)) )
{
wcstring ent;
- while (wreaddir(dir, ent))
+ bool is_dir;
+ while (wreaddir(dir, ent, &is_dir))
{
- if( ent == base_name )
+ if (string_prefixes_string(base_name, ent) && (! require_dir || is_dir))
{
res = true;
break;
@@ -979,7 +980,9 @@ void highlight_shell( const wchar_t * const buff, int *color, int pos, wcstring_
{
for( i=tok_begin-buff; i < (tok_end-buff); i++ )
{
- color[i] |= HIGHLIGHT_VALID_PATH;
+ // Don't color HIGHLIGHT_ERROR because it looks dorky. For example, trying to cd into a non-directory would show an underline and also red.
+ if (! (color[i] & HIGHLIGHT_ERROR))
+ color[i] |= HIGHLIGHT_VALID_PATH;
}
}
}