diff --git a/haskell/System/Console/Isocline.hs b/haskell/System/Console/Isocline.hs
--- a/haskell/System/Console/Isocline.hs
+++ b/haskell/System/Console/Isocline.hs
@@ -56,7 +56,7 @@
 completer :: `CompletionEnv` -> String -> IO () 
 completer cenv input
   = do `completeFileName` cenv input Nothing [\".\",\"\/usr\/local\"] [\".hs\"]  -- use [] for any extension
-       `completeWord` cenv input wcompleter
+       `completeWord` cenv input Nothing wcompleter
 
 wcompleter :: String -> [`Completion`]
 wcompleter input
@@ -231,7 +231,7 @@
 
 -- | @readline prompt@: Read (multi-line) input from the user with rich editing abilities. 
 -- Takes the prompt text as an argument. The full prompt is the combination
--- of the given prompt and the promp marker (@\"> \"@ by default) .
+-- of the given prompt and the prompt marker (@\"> \"@ by default) .
 -- See also 'readlineEx', 'readlineMaybe', 'enableMultiline', and 'setPromptMarker'.
 readline :: String -> IO String  
 readline prompt
@@ -356,7 +356,7 @@
   replacement :: String,  -- ^ actual replacement
   display :: String,      -- ^ display of the completion in the completion menu
   help :: String          -- ^ help message 
-}
+} deriving (Eq, Show)
 
 -- | Create a completion with just a replacement
 completion :: String -> Completion
@@ -1043,4 +1043,4 @@
 withUTF8String str action
   = do let bstr = TE.encodeUtf8 (T.pack str)
        B.useAsCString bstr action
-       
+       
diff --git a/isocline.cabal b/isocline.cabal
--- a/isocline.cabal
+++ b/isocline.cabal
@@ -1,11 +1,11 @@
-cabal-version: 1.12
+cabal-version: 1.12
 
 -- This file has been generated from package.yaml by hpack version 0.34.4.
 --
 -- see: https://github.com/sol/hpack
 
 name:           isocline
-version:        1.0.5
+version:        1.0.6
 synopsis:       A portable alternative to GNU Readline
 description:    ![logo](https://raw.githubusercontent.com/daanx/isocline/main/doc/isocline-inline.svg) A Haskell wrapper around the [Isocline C library](https://github.com/daanx/isocline#readme) which can provide an alternative to GNU Readline. (The Isocline library is included whole and there are no runtime dependencies).
                 Please see the [readme](https://github.com/daanx/isocline/haskell#readme) on GitHub for more information.
diff --git a/src/term.c b/src/term.c
--- a/src/term.c
+++ b/src/term.c
@@ -154,6 +154,7 @@
 }
 
 ic_private void term_set_attr( term_t* term, attr_t attr ) {
+  if (term->nocolor) return;
   if (attr.x.color != term->attr.x.color && attr.x.color != IC_COLOR_NONE) {
     term_color(term,attr.x.color);
     if (term->palette < ANSIRGB && color_is_rgb(attr.x.color)) {
@@ -177,7 +178,7 @@
   }
   if (attr.x.italic != term->attr.x.italic && attr.x.italic != IC_NONE) {
     term_italic(term,attr.x.italic == IC_ON);
-  }
+  }  
   assert(attr.x.color == term->attr.x.color || attr.x.color == IC_COLOR_NONE);
   assert(attr.x.bgcolor == term->attr.x.bgcolor || attr.x.bgcolor == IC_COLOR_NONE);
   assert(attr.x.bold == term->attr.x.bold || attr.x.bold == IC_NONE);
@@ -331,10 +332,10 @@
   if (term == NULL) return NULL;
 
   term->fd_out  = (fd_out < 0 ? STDOUT_FILENO : fd_out);
-  term->nocolor = nocolor;
+  term->nocolor = nocolor || (isatty(term->fd_out) == 0);
   term->silent  = silent;  
   term->mem     = mem;
-  term->tty     = tty;
+  term->tty     = tty;     // can be NULL
   term->width   = 80;
   term->height  = 25;
   term->is_utf8 = tty_is_utf8(tty);
@@ -347,42 +348,43 @@
   if (getenv("NO_COLOR") != NULL) {
     term->nocolor = true;
   }
-
-  // detect color palette
-  // COLORTERM takes precedence
-  const char* colorterm = getenv("COLORTERM");  
-  const char* eterm = getenv("TERM");    
-  if (ic_contains(colorterm,"24bit") || ic_contains(colorterm,"truecolor") || ic_contains(colorterm,"direct")) { 
-    term->palette = ANSIRGB; 
-  }
-  else if (ic_contains(colorterm,"8bit") || ic_contains(colorterm,"256color")) { term->palette = ANSI256; } 
-  else if (ic_contains(colorterm,"4bit") || ic_contains(colorterm,"16color"))  { term->palette = ANSI16; }
-  else if (ic_contains(colorterm,"3bit") || ic_contains(colorterm,"8color"))   { term->palette = ANSI8; }
-  else if (ic_contains(colorterm,"1bit") || ic_contains(colorterm,"nocolor") || ic_contains(colorterm,"monochrome")) { 
-    term->palette = MONOCHROME; 
-  }
-  // otherwise check for some specific terminals
-  else if (getenv("WT_SESSION") != NULL) { term->palette = ANSIRGB; } // Windows terminal
-  else if (getenv("ITERM_SESSION_ID") != NULL) { term->palette = ANSIRGB; } // iTerm2 terminal
-  else if (getenv("VSCODE_PID") != NULL) { term->palette = ANSIRGB; } // vscode terminal
-  else {
-    // and otherwise fall back to checking TERM
-    if (ic_contains(eterm,"truecolor") || ic_contains(eterm,"direct") || ic_contains(colorterm,"24bit")) {
-      term->palette = ANSIRGB;
-    }
-    else if (ic_contains(eterm,"alacritty") || ic_contains(eterm,"kitty")) {
-      term->palette = ANSIRGB;
+  if (!term->nocolor) {
+    // detect color palette
+    // COLORTERM takes precedence
+    const char* colorterm = getenv("COLORTERM");  
+    const char* eterm = getenv("TERM");    
+    if (ic_contains(colorterm,"24bit") || ic_contains(colorterm,"truecolor") || ic_contains(colorterm,"direct")) { 
+      term->palette = ANSIRGB; 
     }
-    else if (ic_contains(eterm,"256color") || ic_contains(eterm,"gnome")) { 
-      term->palette = ANSI256;
-    }  
-    else if (ic_contains(eterm,"16color")){ term->palette = ANSI16; }
-    else if (ic_contains(eterm,"8color")) { term->palette = ANSI8; }
-    else if (ic_contains(eterm,"monochrome") || ic_contains(eterm,"nocolor") || ic_contains(eterm,"dumb")) { 
+    else if (ic_contains(colorterm,"8bit") || ic_contains(colorterm,"256color")) { term->palette = ANSI256; } 
+    else if (ic_contains(colorterm,"4bit") || ic_contains(colorterm,"16color"))  { term->palette = ANSI16; }
+    else if (ic_contains(colorterm,"3bit") || ic_contains(colorterm,"8color"))   { term->palette = ANSI8; }
+    else if (ic_contains(colorterm,"1bit") || ic_contains(colorterm,"nocolor") || ic_contains(colorterm,"monochrome")) { 
       term->palette = MONOCHROME; 
     }
+    // otherwise check for some specific terminals
+    else if (getenv("WT_SESSION") != NULL) { term->palette = ANSIRGB; } // Windows terminal
+    else if (getenv("ITERM_SESSION_ID") != NULL) { term->palette = ANSIRGB; } // iTerm2 terminal
+    else if (getenv("VSCODE_PID") != NULL) { term->palette = ANSIRGB; } // vscode terminal
+    else {
+      // and otherwise fall back to checking TERM
+      if (ic_contains(eterm,"truecolor") || ic_contains(eterm,"direct") || ic_contains(colorterm,"24bit")) {
+        term->palette = ANSIRGB;
+      }
+      else if (ic_contains(eterm,"alacritty") || ic_contains(eterm,"kitty")) {
+        term->palette = ANSIRGB;
+      }
+      else if (ic_contains(eterm,"256color") || ic_contains(eterm,"gnome")) { 
+        term->palette = ANSI256;
+      }  
+      else if (ic_contains(eterm,"16color")){ term->palette = ANSI16; }
+      else if (ic_contains(eterm,"8color")) { term->palette = ANSI8; }
+      else if (ic_contains(eterm,"monochrome") || ic_contains(eterm,"nocolor") || ic_contains(eterm,"dumb")) { 
+        term->palette = MONOCHROME; 
+      }
+    }
+    debug_msg("term: color-bits: %d (COLORTERM=%s, TERM=%s)\n", term_get_color_bits(term), colorterm, eterm);
   }
-  debug_msg("term: color-bits: %d (COLORTERM=%s, TERM=%s)\n", term_get_color_bits(term), colorterm, eterm);
   
   // read COLUMS/LINES from the environment for a better initial guess.
   const char* env_columns = getenv("COLUMNS");
@@ -1028,14 +1030,15 @@
   // this seems to be unreliable on some systems (Ubuntu+Gnome terminal) so only enable when known ok.
   #if __APPLE__
   // otherwise use OSC 4 escape sequence query
-  tty_start_raw(term->tty);
-  for(ssize_t i = 0; i < 16; i++) {
-    uint32_t color;
-    if (!term_esc_query_color_raw(term, i, &color)) break;
-    debug_msg("term ansi color %d: 0x%06x\n", i, color);
-    ansi256[i] = color;
-  }  
-  tty_end_raw(term->tty);  
+  if (tty_start_raw(term->tty)) {
+    for(ssize_t i = 0; i < 16; i++) {
+      uint32_t color;
+      if (!term_esc_query_color_raw(term, i, &color)) break;
+      debug_msg("term ansi color %d: 0x%06x\n", i, color);
+      ansi256[i] = color;
+    }  
+    tty_end_raw(term->tty);  
+  }
   #endif
 }
 
diff --git a/src/tty.c b/src/tty.c
--- a/src/tty.c
+++ b/src/tty.c
@@ -647,6 +647,7 @@
 #endif
 
 ic_private bool tty_start_raw(tty_t* tty) {
+  if (tty == NULL) return false;
   if (tty->raw_enabled) return true;
   if (tcsetattr(tty->fd_in,TCSAFLUSH,&tty->raw_ios) < 0) return false;  
   tty->raw_enabled = true;
@@ -654,6 +655,7 @@
 }
 
 ic_private void tty_end_raw(tty_t* tty) {
+  if (tty == NULL) return;
   if (!tty->raw_enabled) return;
   tty->cpush_count = 0;
   if (tcsetattr(tty->fd_in,TCSAFLUSH,&tty->orig_ios) < 0) return;
