Lines 38-43
Link Here
|
38 |
import java.lang.reflect.Method; |
38 |
import java.lang.reflect.Method; |
39 |
import java.lang.reflect.InvocationTargetException; |
39 |
import java.lang.reflect.InvocationTargetException; |
40 |
|
40 |
|
|
|
41 |
import bsh.util.BshCompleter; |
42 |
import bsh.util.NameCompletionTable; |
43 |
import bsh.classpath.ClassManagerImpl; |
44 |
import org.gnu.readline.Readline; |
45 |
import org.gnu.readline.ReadlineLibrary; |
46 |
import org.gnu.readline.ReadlineReader; |
47 |
|
41 |
/** |
48 |
/** |
42 |
The BeanShell script interpreter. |
49 |
The BeanShell script interpreter. |
43 |
|
50 |
|
Lines 394-403
Link Here
|
394 |
else |
401 |
else |
395 |
src = System.in; |
402 |
src = System.in; |
396 |
|
403 |
|
397 |
Reader in = new CommandLineReader( new InputStreamReader(src)); |
404 |
Reader in = null; |
398 |
Interpreter interpreter = |
405 |
boolean usingReadline = false; |
399 |
new Interpreter( in, System.out, System.err, true ); |
406 |
String backingLib = System.getProperty("bsh.console.readlinelib"); System.out.println("backingLib is " + backingLib); |
400 |
interpreter.run(); |
407 |
if (backingLib != null && backingLib.length() > 0) { |
|
|
408 |
try { |
409 |
File history = new File(System.getProperty("user.home") + |
410 |
File.separator + ".bsh_history"); |
411 |
if (!history.exists()) { |
412 |
try { |
413 |
history.createNewFile(); |
414 |
} catch(IOException ioe) { |
415 |
debug("Unable to create history " + history.getAbsolutePath()); |
416 |
} |
417 |
} |
418 |
ReadlineLibrary lib = ReadlineLibrary.byName(backingLib); |
419 |
// should I wrap CommandLineReader around it? |
420 |
if (history.canWrite() && history.canRead()) { |
421 |
in = new ReadlineReader("bsh % ", history,lib); |
422 |
} else { |
423 |
in = new ReadlineReader("bsh % ",lib); |
424 |
debug("Unable to read/write history " + history.getAbsolutePath()); |
425 |
} |
426 |
} catch (IOException ioe) { |
427 |
System.err.println("Unable to invoke ReadlineReader " + |
428 |
"due to: " + ioe); |
429 |
} |
430 |
} |
431 |
if (in == null) |
432 |
in = new CommandLineReader( new InputStreamReader(src)); |
433 |
else |
434 |
usingReadline = true; |
435 |
Interpreter interpreter = |
436 |
new Interpreter( in, System.out, System.err, true ); |
437 |
if (usingReadline) { |
438 |
NameCompletionTable nct = new NameCompletionTable(); |
439 |
nct.add(interpreter.getNameSpace()); |
440 |
|
441 |
/** ClassManager does a lot of chatting to the stdout, |
442 |
* so this has been commented out for the time being |
443 |
**/ |
444 |
|
445 |
// try { |
446 |
// BshClassManager bcm = BshClassManager.getClassManager(); |
447 |
// if (bcm != null) { |
448 |
// nct.add(((ClassManagerImpl)bcm).getClassPath()); |
449 |
// } |
450 |
// } catch(ClassPathException cpe) { |
451 |
// debug("classpath exception in name compl:" + cpe); |
452 |
// } |
453 |
|
454 |
Readline.setCompleter(new BshCompleter(nct)); |
455 |
} |
456 |
interpreter.run(); |
401 |
} |
457 |
} |
402 |
} |
458 |
} |
403 |
|
459 |
|
Lines 445-451
Link Here
|
445 |
System.err.flush(); |
501 |
System.err.flush(); |
446 |
Thread.yield(); // this helps a little |
502 |
Thread.yield(); // this helps a little |
447 |
|
503 |
|
448 |
if ( interactive ) |
504 |
if ( interactive && !(in instanceof ReadlineReader)) |
449 |
print( getBshPrompt() ); |
505 |
print( getBshPrompt() ); |
450 |
|
506 |
|
451 |
eof = Line(); |
507 |
eof = Line(); |
Lines 548-557
Link Here
|
548 |
} |
604 |
} |
549 |
} |
605 |
} |
550 |
|
606 |
|
551 |
if ( interactive && exitOnEOF ) |
607 |
if ( interactive && exitOnEOF ) { |
552 |
System.exit(0); |
608 |
/* should be done for all streams in general, but this |
|
|
609 |
* ensures that the history for readline is flushed */ |
610 |
try { |
611 |
in.close(); |
612 |
} catch (IOException ioe) { |
613 |
} |
614 |
|
615 |
System.exit(0); |
553 |
} |
616 |
} |
554 |
|
617 |
} |
555 |
// begin source and eval |
618 |
// begin source and eval |
556 |
|
619 |
|
557 |
/** |
620 |
/** |