Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 94987 | Differences between
and this patch

Collapse All | Expand All

(-)BeanShell-2.0b4/src/bsh/Interpreter.java~ (-8 / +71 lines)
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
	/**
(-) (+38 lines)
Added Link Here
1
package bsh.util;
2
3
import org.gnu.readline.ReadlineCompleter;
4
5
/**
6
 * An adapter for org.gnu.readline's ReadlineCompleter interface to map to
7
 * BeanShell's NameCompleter interface.
8
 *
9
 * @see org.gnu.readline.ReadlineReader
10
 * @version $Revision: 1.1 $
11
 * @author Shane Celis <shane@terraspring.com>
12
 **/
13
public class BshCompleter implements ReadlineCompleter {
14
15
    private NameCompletion completer;
16
17
    /**
18
     * Constructs a <code>ReadlineCompleter</code> out of a
19
     * <code>NameCompleter</code> object.
20
     **/
21
    public BshCompleter(NameCompletion completer) {
22
        this.completer = completer;
23
    }
24
25
    /**
26
     * Returns String of completion if unambiguous, otherwise null
27
     **/
28
    public String completer(String text, int state) {
29
        // Not sure what state is used for in ReadlineCompleter
30
        String[] completions = completer.completeName(text);
31
        if (completions.length == 1 && state == 0) {
32
            return completions[0];
33
        } else {
34
            return null;        // ambiguous result
35
        }
36
    }
37
38
}

Return to bug 94987