home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / PersonalPreferences / Text_Console.m < prev   
Text File  |  1992-08-24  |  975b  |  40 lines

  1. //
  2. //    A category on Text to allow for formated printf input.
  3. //    Sam Streeper
  4. //        Copyright NeXT Computer, Inc 1992 All Rights Reserved
  5. //
  6. //    Created 8-24-92
  7. //
  8. //    You may freely copy, distribute and reuse the code in this example.
  9. //    NeXT disclaims any warranty of any kind, expressed or implied, as to
  10. //    its fitness for any particular use.
  11. //
  12.  
  13. #import "Text_Console.h"
  14. #import <stdarg.h>
  15.  
  16. @implementation Text(Text_Console)
  17. #define BUFFERSIZE 512
  18.  
  19. - (int) printf:(const char *) format, ...
  20. {
  21.   int result, length = [self textLength];
  22.   char buffer[BUFFERSIZE];
  23.   va_list    ap;
  24.   
  25.   va_start(ap, format);
  26.   result = vsprintf(buffer, format, ap);
  27.   va_end(ap);
  28.  
  29.   // this is how one puts text into a Text object and goes to that selection.
  30.  
  31.   // put the cursor in the very last location and push the buffer in
  32.   [[self setSel:length :length] replaceSel:buffer];
  33.  
  34.   // scroll so that it is visible and redisplay
  35.   [[self scrollSelToVisible] display];
  36.   
  37.   return result;
  38. }
  39. @end
  40.