1 /******************************************************************************* 2 3 A D wrapper around the GNU readline/history file 4 5 The module contains functionalities to manipulate the readline session 6 history (e.g adding lines to the history so when the user would press the 7 up-arrow he would find the old lines). 8 9 Notes: 10 - Requires linking with -lhistory 11 - The user of this module doesn't need to call `using_history()` as its 12 automatically called once this module is imported. 13 14 Copyright: 15 Copyright (c) 2009-2016 dunnhumby Germany GmbH. 16 All rights reserved. 17 18 License: 19 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 20 Alternatively, this file may be distributed under the terms of the Tango 21 3-Clause BSD License (see LICENSE_BSD.txt for details). 22 23 Bear in mind this module provides bindings to an external library that 24 has its own license, which might be more restrictive. Please check the 25 external library license to see which conditions apply for linking. 26 27 *******************************************************************************/ 28 29 module ocean.io.console.readline.History; 30 31 32 import C = ocean.io.console.readline.c.history; 33 import ocean.text.util.StringC; 34 import ocean.meta.types.Qualifiers; 35 36 static this() 37 { 38 // Required by readline to be called before starting the session. 39 // From readline documentation for using_history: 40 // "Begin a session in which the history functions might be used. This 41 // initializes the interactive variables." 42 C.using_history(); 43 } 44 45 /******************************************************************************* 46 47 Add a line to the history of the readline 48 49 Note: 50 If line isn't null-terminated then it's converted to a C null-terminated 51 string before passing it to the C add_history function. 52 Converting to C string might re-allocate the buffer. If you have tight 53 memory constraints, it is highly recommended to provide a null 54 terminated string or make sure that the GC block your buffer is stored 55 in has a spare byte at the end. 56 57 Params: 58 line = the line to add to history 59 60 *******************************************************************************/ 61 62 void addHistory(mstring line) 63 { 64 char* line_ptr = StringC.toCString( line ); 65 C.add_history(line_ptr); 66 }