package Text::SpellChecker::GUI::Curses;

use warnings;
use strict;
use ZConf::GUI;
use Curses::UI;
use String::ShellQuote;

=head1 NAME

Text::SpellChecker::GUI::Curses - Implements the Curses backend to Text::SpellChecker::GUI.

=head1 VERSION

Version 0.0.0


our $VERSION = '0.0.0';


    use Text::SpellChecker::GUI::Curses;

    my $sg = Text::SpellChecker::GUI::Curses->new();

=head1 METHODS

=head2 new

This initilizes the object.

=head3 args hash

=head4 useX

This is if it should try to use X or not. If it is not defined,
ZConf::GUI->useX is used.

=head4 zconf

This is the ZConf object to use. If it is not specified the one in the
object for zcrunner will be used. If neither zconf or zcrunner is specified,
a new one is created.

=head4 zcgui

This is the ZConf::GUI object. A new one will be created if it is


sub new{
	my %args;
		%args= %{$_[1]};

	my $self={error=>undef, errorString=>''};
	bless $self;

	#initilize the ZConf::GUI object if needed
	if (!defined($args{zcgui})) {
		if (!defined($args{zconf})) {
		}else {

		if ($self->{zg}->{error}) {
			$self->{errorString}='Failed to initilize the ZConf::GUI object. error="'.
			                     $self->{zg}->{error}.'" errorString="'
			warn('Text-SpellChecker-GUI new:1: '.$self->{errorString});
			return $self;
	}else {

	#initilize the ZConf object if needed
	if (!defined($args{zconf})) {
	}else {

	#as the GUI stuff is right below this module, use the module above this one

	$self->{terminal}='xterm -rv -e ';
	#if the enviromental variable 'TERMINAL' is set, use 

	return $self;

=head2 check

This checks the specified the specified text for spelling errors.

Only one option is taken and that is the text to be checked.

The returned value is a hash.

=head3 returned hash

=head4 text

This is the the resulting text.

=head4 cancel

If this is defined and true, then the user canceled the check and any changes.

    my %returned=$sg->check($text);
        print "Error!\n";
            print "The check was canceled.";


sub check{
	my $self=$_[0];
	my $text=$_[1];

	my %toreturn;

	#dump this 
	my $file='/tmp/'.rand().rand().rand();
	open(CHECKWRITE, '>', $file);
	print CHECKWRITE $text;

	#the command to be run
	my $command='curses-textspellchecker -f '.$file;
	if ($self->{useX}) {

	my $exitcode=$? >> 8;

		#error if it got a -1... not in path
	if ($? == -1) {
		$self->{errorString}='"curses-textspellchecker" or the terminal is not in the path.';
		warn('Text-SpellChecker-GUI-Curses check:2: '.$self->{errorString});
		return %toreturn;

	if ($? == 0) {
		if (open(READFH, $file)){
			my @textA=<READFH>;
			$toreturn{text}=join('', @textA);
		}else {

		return %toreturn;

	if ($exitcode == 230) {
		return %toreturn;

	#error if it is something other than 0
	if (!($? == 0)) {

		$self->{errorString}='The backend script exited with a non-zero, "'.$exitcode.'"';
		warn('Text-SpellChecker-GUI-Curses check:3: '.$self->{errorString});
		return %toreturn;		

	return %toreturn;

=head2 dialogs

This returns the available dailogs.


sub dialogs{
	return ('check');

=head2 windows

This returns a list of available windows.


sub windows{
	return undef;

=head2 errorblank

This blanks the error storage and is only meant for internal usage.

It does the following.



#blanks the error flags
sub errorblank{
	my $self=$_[0];


	return 1;


=head2 1

Failed to initiate ZConf::GUI.

=head2 2

Failed to find the required commands in the path.

=head2 3

Failed to read temp file.

=head1 AUTHOR

Zane C. Bowers, C<< <vvelox at> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-text-spellchecker-gui at>, or through
the web interface at L<>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Text::SpellChecker::GUI

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker


=item * AnnoCPAN: Annotated CPAN documentation


=item * CPAN Ratings


=item * Search CPAN





Copyright 2009 Zane C. Bowers, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


1; # End of Text::SpellChecker::GUI::Curses