Index: src/OFStdIOStream.h ================================================================== --- src/OFStdIOStream.h +++ src/OFStdIOStream.h @@ -82,13 +82,50 @@ * @param color The background color to set */ - (void)setBackgroundColor: (OFColor *)color; /*! - * @brief Resets forward and background color. + * @brief Resets all attributes (color, bold, etc.). Does nothing if there is + * no underlying terminal. + */ +- (void)reset; + +/*! + * @brief Clears the entire underlying terminal. Does nothing if there is no + * underlying terminal. + */ +- (void)clear; + +/*! + * @brief Erases the entire current line on the underlying terminal. Does + * nothing if there is no underlying terminal. + */ +- (void)eraseLine; + +/*! + * @brief Moves the cursor to the specified column in the current row. Does + * nothing if there is no underlying terminal. + * + * @param column The column in the current row to move the cursor to + */ +- (void)setCursorColumn: (unsigned int)column; + +/*! + * @brief Moves the cursor to the specified absolute position. Does nothing if + * there is no underlying terminal. + * + * @param position The position to move the cursor to + */ +- (void)setCursorPosition: (of_point_t)position; + +/*! + * @brief Moves the cursor to the specified relative position. Does nothing if + * there is no underlying terminal. + * + * @param position The position to move the cursor to */ -- (void)resetColor; +- (void)setRelativeCursorPosition: (of_point_t)position; @end #ifdef __cplusplus extern "C" { #endif Index: src/OFStdIOStream.m ================================================================== --- src/OFStdIOStream.m +++ src/OFStdIOStream.m @@ -441,15 +441,74 @@ [self writeFormat: @"\033[%um", code + 10]; #endif } -- (void)resetColor +- (void)reset { #ifdef HAVE_ISATTY if (!isatty(_fd)) return; [self writeString: @"\033[0m"]; #endif } + +- (void)clear +{ +#ifdef HAVE_ISATTY + if (!isatty(_fd)) + return; + + [self writeString: @"\033[2J"]; +#endif +} + +- (void)eraseLine +{ +#ifdef HAVE_ISATTY + if (!isatty(_fd)) + return; + + [self writeString: @"\033[2K"]; +#endif +} + +- (void)setCursorColumn: (unsigned int)column +{ +#ifdef HAVE_ISATTY + if (!isatty(_fd)) + return; + + [self writeFormat: @"\033[%uG", column + 1]; +#endif +} + +- (void)setCursorPosition: (of_point_t)position +{ +#ifdef HAVE_ISATTY + if (!isatty(_fd)) + return; + + [self writeFormat: @"\033[%u;%uH", + (unsigned)position.y + 1, (unsigned)position.x + 1]; +#endif +} + +- (void)setRelativeCursorPosition: (of_point_t)position +{ +#ifdef HAVE_ISATTY + if (!isatty(_fd)) + return; + + if (position.x > 0) + [self writeFormat: @"\033[%uC", (unsigned)position.x]; + else if (position.x < 0) + [self writeFormat: @"\033[%uD", (unsigned)-position.x]; + + if (position.y > 0) + [self writeFormat: @"\033[%uB", (unsigned)position.y]; + else if (position.y < 0) + [self writeFormat: @"\033[%uA", (unsigned)-position.y]; +#endif +} @end