packages feed

linenoise 0.4.0 → 0.4.1

raw patch · 6 files changed

+22/−135 lines, 6 files

Files

cbits/linenoise.c view
@@ -880,6 +880,10 @@     l->plen = strlen(prompt);     l->oldpos = l->pos = 0;     l->len = 0;++    /* Enter raw mode. */+    if (enableRawMode(l->ifd) == -1) return -1;+     l->cols = getColumns(stdin_fd, stdout_fd);     l->oldrows = 0;     l->history_index = 0;@@ -892,9 +896,6 @@      * will actually just read a line from standard input in blocking      * mode later, in linenoiseEditFeed(). */     if (!isatty(l->ifd)) return 0;--    /* Enter raw mode. */-    if (enableRawMode(l->ifd) == -1) return -1;      /* The latest history entry is always our current buffer, that      * initially is just an empty string. */
− cbits/linenoise.h
@@ -1,113 +0,0 @@-/* linenoise.h -- VERSION 1.0- *- * Guerrilla line editing library against the idea that a line editing lib- * needs to be 20,000 lines of C code.- *- * See linenoise.c for more information.- *- * ------------------------------------------------------------------------- *- * Copyright (c) 2010-2023, Salvatore Sanfilippo <antirez at gmail dot com>- * Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>- *- * All rights reserved.- *- * Redistribution and use in source and binary forms, with or without- * modification, are permitted provided that the following conditions are- * met:- *- *  *  Redistributions of source code must retain the above copyright- *     notice, this list of conditions and the following disclaimer.- *- *  *  Redistributions in binary form must reproduce the above copyright- *     notice, this list of conditions and the following disclaimer in the- *     documentation and/or other materials provided with the distribution.- *- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT- * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.- */--#ifndef __LINENOISE_H-#define __LINENOISE_H--#ifdef __cplusplus-extern "C" {-#endif--#include <stddef.h> /* For size_t. */--extern char *linenoiseEditMore;--/* The linenoiseState structure represents the state during line editing.- * We pass this state to functions implementing specific editing- * functionalities. */-struct linenoiseState {-    int in_completion;  /* The user pressed TAB and we are now in completion-                         * mode, so input is handled by completeLine(). */-    size_t completion_idx; /* Index of next completion to propose. */-    int ifd;            /* Terminal stdin file descriptor. */-    int ofd;            /* Terminal stdout file descriptor. */-    char *buf;          /* Edited line buffer. */-    size_t buflen;      /* Edited line buffer size. */-    const char *prompt; /* Prompt to display. */-    size_t plen;        /* Prompt length. */-    size_t pos;         /* Current cursor position. */-    size_t oldpos;      /* Previous refresh cursor position. */-    size_t len;         /* Current edited line length. */-    size_t cols;        /* Number of columns in terminal. */-    size_t oldrows;     /* Rows used by last refrehsed line (multiline mode) */-    int history_index;  /* The history index we are currently editing. */-};--typedef struct linenoiseCompletions {-  size_t len;-  char **cvec;-} linenoiseCompletions;--/* Non blocking API. */-int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt);-char *linenoiseEditFeed(struct linenoiseState *l);-void linenoiseEditStop(struct linenoiseState *l);-void linenoiseHide(struct linenoiseState *l);-void linenoiseShow(struct linenoiseState *l);--/* Blocking API. */-char *linenoise(const char *prompt);-void linenoiseFree(void *ptr);--/* Completion API. */-typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);-typedef char*(linenoiseHintsCallback)(const char *, int *color, int *bold);-typedef void(linenoiseFreeHintsCallback)(void *);-void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);-void linenoiseSetHintsCallback(linenoiseHintsCallback *);-void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);-void linenoiseAddCompletion(linenoiseCompletions *, const char *);--/* History API. */-int linenoiseHistoryAdd(const char *line);-int linenoiseHistorySetMaxLen(int len);-int linenoiseHistorySave(const char *filename);-int linenoiseHistoryLoad(const char *filename);--/* Other utilities. */-void linenoiseClearScreen(void);-void linenoiseSetMultiLine(int ml);-void linenoisePrintKeyCodes(void);-void linenoiseMaskModeEnable(void);-void linenoiseMaskModeDisable(void);--#ifdef __cplusplus-}-#endif--#endif /* __LINENOISE_H */
linenoise.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.36.0.+-- This file has been generated from package.yaml by hpack version 0.37.0. -- -- see: https://github.com/sol/hpack ----- hash: 0254782fbfe2bb0d8c7beef670cb12c6e6acd0d2993d01655a777fb0e3a5ac17+-- hash: d7c93d3c5e6b850809e5aae6ce9b3df8784da16908082839f3fef8a267d5fe2e  name:           linenoise-version:        0.4.0+version:        0.4.1 synopsis:       A lightweight readline-replacement library for Haskell description:    Please see the README on GitHub at <https://github.com/ejconlon/haskell-linenoise#readme> category:       User Interfaces@@ -42,7 +42,6 @@       cbits   c-sources:       cbits/linenoise.c-      cbits/linenoise.h   build-depends:       base >=4.12 && <5     , bytestring >=0.10 && <1
src/Linenoise/Completion.hs view
@@ -9,7 +9,7 @@ import qualified Data.Text as Text  -- | Complete by word.-byWord :: Monad m => (Text -> m [Text]) -> (Text -> m [Text])+byWord :: (Monad m) => (Text -> m [Text]) -> (Text -> m [Text]) byWord f line = do   let split = Text.words line   case split of
src/Linenoise/Repl.hs view
@@ -45,7 +45,7 @@     , MonadReader r     ) -askRef :: Applicative m => ReplT r s m (IORef s)+askRef :: (Applicative m) => ReplT r s m (IORef s) askRef = ReplT (ReaderT (const (ReaderT pure)))  refReplT :: ReplT r s m a -> r -> IORef s -> m a@@ -54,18 +54,18 @@ instance MonadTrans (ReplT r s) where   lift = ReplT . lift . lift -instance MonadUnliftIO m => MonadUnliftIO (ReplT r s m) where+instance (MonadUnliftIO m) => MonadUnliftIO (ReplT r s m) where   withRunInIO run = do     r <- ask     ref <- askRef     wrappedWithRunInIO lift (\n -> refReplT n r ref) run -instance MonadIO m => MonadState s (ReplT r s m) where+instance (MonadIO m) => MonadState s (ReplT r s m) where   get = ReplT (ReaderT (const (ReaderT (liftIO . readIORef))))   put s = ReplT (ReaderT (const (ReaderT (\ref -> liftIO (writeIORef ref s)))))  -- | Run a ReplT.-runReplT :: MonadIO m => ReplT r s m a -> r -> s -> m (a, s)+runReplT :: (MonadIO m) => ReplT r s m a -> r -> s -> m (a, s) runReplT n r s = do   ref <- liftIO (newIORef s)   res <- refReplT n r ref@@ -80,7 +80,7 @@  -- | Run a simple REPL. replM-  :: MonadUnliftIO m+  :: (MonadUnliftIO m)   => ReplDirective   -- ^ Directive on interrupt   -> Text
src/Linenoise/Unlift.hs view
@@ -21,39 +21,39 @@ import qualified Linenoise.FFI as FFI  -- | Add to current history.-addHistory :: MonadIO m => Text -> m ()+addHistory :: (MonadIO m) => Text -> m () addHistory = liftIO . FFI.addHistory . encodeUtf8  -- | Clear the screen.-clearScreen :: MonadIO m => m ()+clearScreen :: (MonadIO m) => m () clearScreen = liftIO FFI.clearScreen  -- | Run the prompt, yielding a string.-getInputLine :: MonadIO m => Text -> m (InputResult Text)+getInputLine :: (MonadIO m) => Text -> m (InputResult Text) getInputLine = liftIO . fmap (fmap decodeUtf8) . FFI.getInputLine . encodeUtf8  -- | Load history from a file.-historyLoad :: MonadIO m => FilePath -> m ()+historyLoad :: (MonadIO m) => FilePath -> m () historyLoad = liftIO . FFI.historyLoad  -- | Save history to a file.-historySave :: MonadIO m => FilePath -> m ()+historySave :: (MonadIO m) => FilePath -> m () historySave = liftIO . FFI.historySave  -- | Print keycodes.-printKeycodes :: MonadIO m => m ()+printKeycodes :: (MonadIO m) => m () printKeycodes = liftIO FFI.printKeycodes  -- | Set the current completion function.-setCompletion :: MonadUnliftIO m => (Text -> m [Text]) -> m ()+setCompletion :: (MonadUnliftIO m) => (Text -> m [Text]) -> m () setCompletion f =   let g = fmap (fmap encodeUtf8) . f . decodeUtf8   in  withRunInIO (\runInIO -> FFI.setCompletion (runInIO . g))  -- | Enable/Disable multiline input.-setMultiline :: MonadIO m => Bool -> m ()+setMultiline :: (MonadIO m) => Bool -> m () setMultiline = liftIO . FFI.setMultiline  -- | Limit the maximum history length.-stifleHistory :: MonadIO m => Int -> m ()+stifleHistory :: (MonadIO m) => Int -> m () stifleHistory = liftIO . FFI.stifleHistory