<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# This file was preprocessed, do not edit!


package Debconf::FrontEnd::Dialog;
use warnings;
use strict;
use Debconf::Gettext;
use Debconf::Priority;
use Debconf::TmpFile;
use Debconf::Log qw(:all);
use Debconf::Encoding qw(wrap $columns width);
use Debconf::Path;
use IPC::Open3;
use POSIX;
use Fcntl;
use base qw(Debconf::FrontEnd::ScreenSize);


sub init {
	my $this=shift;

	$this-&gt;SUPER::init(@_);

	delete $ENV{POSIXLY_CORRECT} if exists $ENV{POSIXLY_CORRECT};
	delete $ENV{POSIX_ME_HARDER} if exists $ENV{POSIX_ME_HARDER};

	if (! exists $ENV{TERM} || ! defined $ENV{TERM} || $ENV{TERM} eq '') {
		die gettext("TERM is not set, so the dialog frontend is not usable.")."\n";
	}
	elsif ($ENV{TERM} =~ /emacs/i) {
		die gettext("Dialog frontend is incompatible with emacs shell buffers")."\n";
	}
	elsif ($ENV{TERM} eq 'dumb' || $ENV{TERM} eq 'unknown') {
		die gettext("Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.")."\n";
	}

	$this-&gt;interactive(1);
	$this-&gt;capb('backup');

	if (Debconf::Path::find("whiptail") &amp;&amp;
	    (! defined $ENV{DEBCONF_FORCE_DIALOG} || ! Debconf::Path::find("dialog")) &amp;&amp;
	    (! defined $ENV{DEBCONF_FORCE_XDIALOG} || ! Debconf::Path::find("Xdialog")) &amp;&amp;
	    system('whiptail --version &gt;/dev/null 2&gt;&amp;1') == 0) {
		$this-&gt;program('whiptail');
		$this-&gt;dashsep('--');
		$this-&gt;borderwidth(5);
		$this-&gt;borderheight(6);
		$this-&gt;spacer(1);
		$this-&gt;titlespacer(10);
		$this-&gt;columnspacer(3);
		$this-&gt;selectspacer(13);
		$this-&gt;hasoutputfd(1);
	}
	elsif (Debconf::Path::find("dialog") &amp;&amp;
	       (! defined $ENV{DEBCONF_FORCE_XDIALOG} || ! Debconf::Path::find("Xdialog")) &amp;&amp;
	       system('dialog --version &gt;/dev/null 2&gt;&amp;1') == 0) {
		$this-&gt;program('dialog');
		$this-&gt;dashsep(''); # dialog does not need (or support)
		$this-&gt;borderwidth(7);
		$this-&gt;borderheight(6);
		$this-&gt;spacer(0);
		$this-&gt;titlespacer(4);
		$this-&gt;columnspacer(2);
		$this-&gt;selectspacer(0);
		$this-&gt;hasoutputfd(1);
	}
	elsif (Debconf::Path::find("Xdialog") &amp;&amp; defined $ENV{DISPLAY}) {
		$this-&gt;program("Xdialog");
		$this-&gt;borderwidth(7);
		$this-&gt;borderheight(20);
		$this-&gt;spacer(0);
		$this-&gt;titlespacer(10);
		$this-&gt;selectspacer(0);
		$this-&gt;columnspacer(2);
		$this-&gt;screenheight(200);
	}
	else {
		die gettext("No usable dialog-like program is installed, so the dialog based frontend cannot be used.");
	}

	if ($this-&gt;screenheight &lt; 13 || $this-&gt;screenwidth &lt; 31) {
		die gettext("Dialog frontend requires a screen at least 13 lines tall and 31 columns wide.")."\n";
	}
}


sub sizetext {
	my $this=shift;
	my $text=shift;

	$columns = $this-&gt;screenwidth - $this-&gt;borderwidth - $this-&gt;columnspacer;
	$text=wrap('', '', $text);
	my @lines=split(/\n/, $text);

	my $window_columns=width($this-&gt;title) + $this-&gt;titlespacer;
	map {
		my $w=width($_);
		$window_columns = $w if $w &gt; $window_columns;
	} @lines;

	return $text, $#lines + 1 + $this-&gt;borderheight,
	       $window_columns + $this-&gt;borderwidth;
}


sub ellipsize {
	my $this=shift;
	my $text=shift;

	return $text if $this-&gt;program ne 'whiptail';

	$columns = $this-&gt;screenwidth - $this-&gt;borderwidth - $this-&gt;columnspacer - $this-&gt;selectspacer;
	if (width($text) &gt; $columns) {
		$columns -= 3;
		$text = (split(/\n/, wrap('', '', $text), 2))[0] . '...';
	}
	return $text;
}


sub hide_escape {
	my $line = $_;

	$line =~ s/\\n/\\\xe2\x81\xa0n/g;
	return $line;
}


sub showtext {
	my $this=shift;
	my $question=shift;
	my $intext=shift;

	my $lines = $this-&gt;screenheight;
	my ($text, $height, $width)=$this-&gt;sizetext($intext);

	my @lines = split(/\n/, $text);
	my $num;
	my @args=('--msgbox', join("\n", @lines));
	if ($lines - 4 - $this-&gt;borderheight &lt;= $#lines) {
		$num=$lines - 4 - $this-&gt;borderheight;
		if ($this-&gt;program eq 'whiptail') {
			push @args, '--scrolltext';
		}
		else {
			my $fh=Debconf::TmpFile::open();
			print $fh join("\n", map { &amp;hide_escape } @lines);
			close $fh;
			@args=("--textbox", Debconf::TmpFile::filename());
		}
	}
	else {
		$num=$#lines + 1;
	}
	$this-&gt;showdialog($question, @args, $num + $this-&gt;borderheight, $width);
	if ($args[0] eq '--textbox') {
		Debconf::TmpFile::cleanup();
	}
}


sub makeprompt {
	my $this=shift;
	my $question=shift;
	my $freelines=$this-&gt;screenheight - $this-&gt;borderheight + 1;
	$freelines += shift if @_;

	my ($text, $lines, $columns)=$this-&gt;sizetext(
		$question-&gt;extended_description."\n\n".
		$question-&gt;description
	);

	if ($lines &gt; $freelines) {
		$this-&gt;showtext($question, $question-&gt;extended_description);
		($text, $lines, $columns)=$this-&gt;sizetext($question-&gt;description);
	}

	return ($text, $lines, $columns);
}

sub startdialog {
	my $this=shift;
	my $question=shift;
	my $wantinputfd=shift;

	debug debug =&gt; "preparing to run dialog. Params are:" ,
		join(",", $this-&gt;program, @_);

	our ($saveout, $savein);
	open($saveout, "&gt;&amp;", \*STDOUT) || die $!;
	$this-&gt;dialog_saveout($saveout);
	if ($wantinputfd) {
		$this-&gt;dialog_savein(undef);
	} else {
		open($savein, "&lt;&amp;", \*STDIN) || die $!;
		$this-&gt;dialog_savein($savein);
	}

	$this-&gt;dialog_savew($^W);
	$^W=0;

	unless ($this-&gt;capb_backup || grep { $_ eq '--defaultno' } @_) {
		if ($this-&gt;program ne 'Xdialog') {
			unshift @_, '--nocancel';
		}
		else {
			unshift @_, '--no-cancel';
		}
	}

	if ($this-&gt;program eq 'Xdialog' &amp;&amp; $_[0] eq '--passwordbox') {
		$_[0]='--password --inputbox'
	}

	use vars qw{*OUTPUT_RDR *OUTPUT_WTR};
	if ($this-&gt;hasoutputfd) {
		pipe(OUTPUT_RDR, OUTPUT_WTR) || die "pipe: $!";
		my $flags=fcntl(\*OUTPUT_WTR, F_GETFD, 0);
		fcntl(\*OUTPUT_WTR, F_SETFD, $flags &amp; ~FD_CLOEXEC);
		$this-&gt;dialog_output_rdr(\*OUTPUT_RDR);
		unshift @_, "--output-fd", fileno(\*OUTPUT_WTR);
	}

	my $backtitle='';
	if (defined $this-&gt;info) {
		$backtitle = $this-&gt;info-&gt;description;
	} else {
		$backtitle = gettext("Package configuration");
	}

	use vars qw{*INPUT_RDR *INPUT_WTR};
	if ($wantinputfd) {
		pipe(INPUT_RDR, INPUT_WTR) || die "pipe: $!";
		autoflush INPUT_WTR 1;
		my $flags=fcntl(\*INPUT_RDR, F_GETFD, 0);
		fcntl(\*INPUT_RDR, F_SETFD, $flags &amp; ~FD_CLOEXEC);
		$this-&gt;dialog_input_wtr(\*INPUT_WTR);
	} else {
		$this-&gt;dialog_input_wtr(undef);
	}

	use vars qw{*ERRFH};
	my $pid = open3($wantinputfd ? '&lt;&amp;INPUT_RDR' : '&lt;&amp;STDIN', '&gt;&amp;STDOUT',
		\*ERRFH, $this-&gt;program,
		'--backtitle', $backtitle,
		'--title', $this-&gt;title, @_);
	$this-&gt;dialog_errfh(\*ERRFH);
	$this-&gt;dialog_pid($pid);
	close OUTPUT_WTR if $this-&gt;hasoutputfd;
}

sub waitdialog {
	my $this=shift;

	my $input_wtr=$this-&gt;dialog_input_wtr;
	if ($input_wtr) {
		close $input_wtr;
	}
	my $output_rdr=$this-&gt;dialog_output_rdr;
	my $errfh=$this-&gt;dialog_errfh;
	my $output='';
	if ($this-&gt;hasoutputfd) {
		while (&lt;$output_rdr&gt;) {
			$output.=$_;
		}
		my $error=0;
		while (&lt;$errfh&gt;) {
			print STDERR $_;
			$error++;
		}
		if ($error) {
			die sprintf("debconf: %s output the above errors, giving up!", $this-&gt;program)."\n";
		}
	}
	else {
		while (&lt;$errfh&gt;) { # ugh
			$output.=$_;
		}
	}
	chomp $output;

	waitpid($this-&gt;dialog_pid, 0);
	$^W=$this-&gt;dialog_savew;

	if (defined $this-&gt;dialog_savein) {
		open(STDIN, '&lt;&amp;', $this-&gt;dialog_savein) || die $!;
	}
	open(STDOUT, '&gt;&amp;', $this-&gt;dialog_saveout) || die $!;

	my $ret=$? &gt;&gt; 8;
	if ($ret == 255 || ($ret == 1 &amp;&amp; join(' ', @_) !~ m/--yesno\s/)) {
		$this-&gt;backup(1);
		return;
	}

	if (wantarray) {
		return $ret, $output;
	}
	else {
		return $output;
	}
}


sub showdialog {
	my $this=shift;
	my $question=shift;

	@_=map { &amp;hide_escape } @_;

	if (defined $this-&gt;progress_bar) {
		$this-&gt;progress_bar-&gt;stop;
	}

	$this-&gt;startdialog($question, 0, @_);
	my (@ret, $ret);
	if (wantarray) {
		@ret=$this-&gt;waitdialog(@_);
	} else {
		$ret=$this-&gt;waitdialog(@_);
	}

	if (defined $this-&gt;progress_bar) {
		$this-&gt;progress_bar-&gt;start;
	}

	if (wantarray) {
		return @ret;
	} else {
		return $ret;
	}
}


1
</pre></body></html>